ncc icon indicating copy to clipboard operation
ncc copied to clipboard

Cannot find module

Open dinkoivanov opened this issue 5 years ago • 3 comments

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:

  1. 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);
}
  1. Create a settings.json file with content: {}.
  2. Execute: ncc build app.js -o .
  3. 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.

dinkoivanov avatar Feb 02 '21 16:02 dinkoivanov

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?

louisgv avatar Oct 15 '21 22:10 louisgv

How did you solve it?

zhu956645239 avatar May 23 '22 05:05 zhu956645239

Error: Cannot find module 'node:http'

gokaybiz avatar Dec 13 '23 08:12 gokaybiz