[BUG] Crash when Node starts from ESM module
sla100 opened this issue · 1 comments
sla100 commented
When
Use @npmcli/config
from ESM
Nodejs code.
How
Current Behavior
TypeError: Cannot read property 'filename' of undefined
at setEnvs (C:\npm-config-issue\node_modules\@npmcli\config\lib\set-envs.js:95:35)
Steps to Reproduce
// test.mjs
import Config from '@npmcli/config';
new Config({ types:{}, npmPath:'', defaults: {} }).load();
npm i @npmcli/config semver
node ./test.mjs
Expected Behavior
No error
References
// @npmcli/config/lib/set-envs.js:95
// is
env.npm_execpath = require.main.filename
// should be
env.npm_execpath = require.main?.filename
// because require.main is empty when Node start with ESM main module