You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
require.main is undefined when using --experimental-modules #21143
When running node with --experimental-modules flag, the global require object has a main property but its value is always undefined. Is this by design?
I was expecting to be no difference in behavior (using the flag or not).
I thought .js files are considered cjs (by default) even when using --experimental-modules.
p.s. all the other properties of require object 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.
Activity
bnoordhuis commentedon Jun 5, 2018
What would you expect it to print? Without
--experimental-modulesit's the CJSModuleobject.mgalakos commentedon Jun 5, 2018
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.bnoordhuis commentedon Jun 5, 2018
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.
mgalakos commentedon Jun 5, 2018
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.maindevsnek commentedon 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.
guybedford commentedon Jun 5, 2018
Agreed this is a bug, had just put on my list to fix too.
vsnehil92 commentedon Jun 6, 2018
@guybedford Is this issue still open?
ljharb commentedon Jun 6, 2018
@vsnehil92 yes, because the linked PR #21150 hasn't yet been merged.
vsnehil92 commentedon Jun 6, 2018
@ljharb The changes have already been approved.
ljharb commentedon Jun 6, 2018
yes, but issues typically stay open til the PR is merged.
targos commentedon Jun 13, 2018
#21150 was merged. Closing.