You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when i use the pkg pack the index.js , pkg dist/index.js --targets node14-macos-x64,this is generate the index binary package,but when i run the package i got the error :Error reading config file: Error: File '/**/dist/config.json' was not included into executable at compilation stage. Please recompile adding it as asset or script.
(base) ➜ test-node-pkg-to-exe tree
.
├── config.json
├── dist
│ ├── config.json
│ └── index.js
├── main.js
└── package.json
2 directories, 5 files
config.json
{ "appname": "myapp" }
main.js
`
const fs = require("fs");
const path = require("path");
const axios = require("axios");
let cfgPath = path.join(__dirname, "config.json");
fs.readFile(cfgPath, "utf8", (err, data) => {
if (err) {
console.error("Error reading config file:", err);
process.exit(1);
}
});
setInterval(() => {
console.log("isRunning...");
}, 1000);
`
and then i run the command--->ncc build main,it generate the dist dir,and the index.js last lines like this
`
const fs = nccwpck_require(147);
const path = nccwpck_require(17);
const axios = nccwpck_require(515);
let cfgPath = nccwpck_require.ab + "config.json";
fs.readFile(nccwpck_require.ab + "config.json", "utf8", (err, data) => {
if (err) {
console.error("Error reading config file:", err);
process.exit(1);
}
});
setInterval(() => {
console.log("isRunning...");
}, 1000);
})();
`
the node of path is not use!!!!
when i use the pkg pack the index.js , pkg dist/index.js --targets node14-macos-x64,this is generate the index binary package,but when i run the package i got the error :Error reading config file: Error: File '/**/dist/config.json' was not included into executable at compilation stage. Please recompile adding it as asset or script.
and then i try to modify the dist/index.js
`
const fs = nccwpck_require(147);
const path = nccwpck_require(17);
const axios = nccwpck_require(515);
let cfgPath = path.join(__dirname, "config.json");
fs.readFile(cfgPath, "utf8", (err, data) => {
if (err) {
console.error("Error reading config file:", err);
process.exit(1);
}
});
setInterval(() => {
console.log("isRunning...");
}, 1000);
`
and then use pkg pack the application:pkg dist/index.js --targets node14-macos-x64, i run the index is success !
so,this is a bug of ncc or pkg?
The text was updated successfully, but these errors were encountered: