Repository navigation
require.main is undefined when using --experimental-modules #21143
Description
Activity
- addedquestionIssues asking questions about Node.js.Issues asking questions about Node.js.esmIssues and PRs related to the ECMAScript Modules implementation.Issues and PRs related to the ECMAScript Modules implementation.
on Jun 5, 2018 What would you expect it to print? Without
--experimental-modulesit's the CJSModuleobject.I was expecting to be no difference in behavior (using the flag or not).
I thought.jsfiles are consideredcjs(by default) even when using--experimental-modules.p.s. all the other properties of
requireobject have almost identical values.I thought .js files are considered cjs (by default) even when using --experimental-modules.
Yes, but they don't use the traditional module loader where
require.main === process.mainModule.The new module loader doesn't really have a concept of "main-ness" right now and I don't know if that is something that ought to be fixed. One for @nodejs/modules to consider.
Oh i see, thank you for your quick response.
Maybe this should be solved before esm support drop experimental status, because it will break all
cjsmodules that rely onrequire.main- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Jun 5, 2018 I found this a few weeks ago but wasn't sure how to fix it, I'll take another look before friday.
Agreed this is a bug, had just put on my list to fix too.
@guybedford Is this issue still open?
@vsnehil92 yes, because the linked PR #21150 hasn't yet been merged.
@ljharb The changes have already been approved.
yes, but issues typically stay open til the PR is merged.
Reacted by vsnehil#21150 was merged. Closing.
Reacted by Jordan Harband
When running node with --experimental-modules flag, the global
requireobject has amainproperty but its value is alwaysundefined. Is this by design?