Cannot find module
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 9.8k
- Forks
- 326
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with app.js, settings.json, Node 14.15.2, and ncc 0.23.0 versus 0.27.0 using the documented ncc build command. Inspect the generated index.js around the webpackEmptyContext failure and compare it with the case where fs.existsSync is extracted; done means the packaged application can load the existing settings.json without MODULE_NOT_FOUND.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100