ncc
ncc copied to clipboard
Cannot find module
Hi,
I hit a problem after migrating from ncc 0.23.0 to 0.27.0. I'm using node 14.15.2.
To reproduce:
- Create an app.js file with the following content:
const fs = require('fs');
let settingsPath = './settings.json';
if (fs.existsSync(settingsPath)) {
let settings = require(settingsPath);
console.log(settings);
}
- Create a settings.json file with content:
{}. - Execute:
ncc build app.js -o . - Run the packaged application using `node index.js. This will result in the following error:
Error: Cannot find module './settings.json'
at webpackEmptyContext (C:\projects\auroramm\sample123\index.js:21:10)
at Object.498 (C:\projects\auroramm\sample123\index.js:11:44)
at __nccwpck_require__ (C:\projects\auroramm\sample123\index.js:61:42)
at C:\projects\auroramm\sample123\index.js:83:18
at Object.<anonymous> (C:\projects\auroramm\sample123\index.js:84:12)
[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:928:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:769:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)[39m {
code: [32m'MODULE_NOT_FOUND'[39m
}
Note that extracting the fs.existsSync() call in a separate variable produces proper result.
I'm having a similar issue with dynamic import upon upgrading to 0.31.1 from 0.30.0
0.30.0 worked and it' outputs a lot of index files, vs 0.31.1 where it output only a single file?
How did you solve it?
Error: Cannot find module 'node:http'