Reputation: 9
I have my project in node.js and express.js. i need to make an executable of node.js project.
Project configuration :
Using ES6 features : import and dynamic import, and for this babel.js , i am using.
Project status :
Project is running correctly no problem.
Transpiling of the project is working. That is bundling creation is ok.
Problem/Error/Issue :
while packaging with command :
pkg . --debug
it giving error of ' import'
package.json configuration :
{
"name": "server",
"version": "0.0.0",
"private": true,
"bin": "./app.js",
"main":"./app.js",
"engines": {
"node": ">=6"
},
"scripts": {
"start": "nodemon app.js --exec babel-node",
"test": "nodemon NODE_ENV=development",
"build": "webpack --config build/webpack.config.js --progress true --display-error-details true"
},
"dependencies": {
"nodemailer": "^4.6.6",
"protractor": "^5.3.2",
"pug": "^2.0.3",
"request": "^2.79.0",
"serve-favicon": "*",
"underscore": "^1.9.1",
"winston": "^2.4.1"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"babel-loader": "^8.0.4",
"babel-plugin-dynamic-import-node": "^2.1.0",
"html-webpack-plugin": "^3.2.0",
"nodemon": "*",
"pkg": "^4.3.4",
"rimraf": "^2.6.1",
"script-ext-html-webpack-plugin": "^2.0.1",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
},
"pkg": {
"scripts": [
"node_modules/*",
"build/output/main.bundle.js"
],
"assets": [
"views/**/*",
"public/*"
],
"targets": [
"node8"
]
}
}
webapck.config.js :
module.exports = {
node: {
__dirname: true,
__filename: true
},
target: 'node',
mode: 'development',
entry: ["./app.js"],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'output')
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
resolve: {
extensions: [".js",".json"]
},
use: [{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env'
],
plugins: [
'@babel/plugin-transform-runtime'
]
}
}]
}
],
exprContextRegExp: /$^/,
exprContextCritical: false
}
};
Error that i am getting :
> Warning Failed to make bytecode node8-x64 for file C:\snapshot\server\app\modules\v1\user\routes\routes.js
C:\snapshot\server\app\modules\v1\user\routes\admin-routes.js:1
(function (exports, require, module, __filename, __dirname) { import {
^^^^^^
SyntaxError: Unexpected token import
at Socket.<anonymous> ([eval]:18:19)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at Pipe.onread (net.js:597:20)
C:\snapshot\pickcel-server\app\modules\v1\user\routes\admin-routes.js:1
(function (exports, require, module, __filename, __dirname) { import {
^^^^^^
What will be the reason ??
Can someone give some suggestion or strategy ?
Regards
Upvotes: 0
Views: 2744
Reputation: 203359
pkg .
will use the bin
property of package.json
and use that to determine the entry file, which in your case is app.js
.
Assuming that that file isn't transpiled, and you want to package the transpiled bundle, try this:
pkg build/output/main.bundle.js --debug
Upvotes: 1