-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self referential modules not supported in repl or -r
#31595
Comments
Note you need to add an “exports” main for self resolution to work.
…On Fri, Jan 31, 2020 at 22:32 Myles Borins ***@***.***> wrote:
If you attempt to require('package-name') using v13.7.0 in the repl it
will fail with a 'MODULE_NOT_FOUND' error.
// index.jsconsole.log('yay')// package.json
{
"name": "ohno",
"main": "./index.js"
}
Uncaught Error: Cannot find module 'ohno'
Require stack:
- at Function.Module._resolveFilename
(internal/modules/cjs/loader.js:980:15) at Function.Module._load
(internal/modules/cjs/loader.js:862:27) at Module.require
(internal/modules/cjs/loader.js:1040:19) at require
(internal/modules/cjs/helpers.js:72:18) { code: 'MODULE_NOT_FOUND',
requireStack: [ '' ]
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#31595?email_source=notifications&email_token=AAESFSTONW5SWBLGAB6G4UDRASDF3A5CNFSM4KONFOPKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IKH3U2Q>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAESFSUSMJ2YEDFLKWDQNVLRASDF3ANCNFSM4KONFOPA>
.
|
I would like to try to help on this issue. I am trying a few things and for what I have seen so far in the commonjs loader, at this line the self resolution is skipped because the |
@dnlup the I just did a quick test of this with the following structure: package.json
index.js require('pkg'); pkg.js console.log('it works'); and can confirm this is working ok, so will close this issue. If you are still finding any inconsistencies though please do let me know - the fact that you also ran into this means that there may be some documentation gaps that we need to do a better job of filling where the catch is happening here. |
Sorry I misread this is specifically about calling from the repl. In the case of the repl, strictly speaking can we consider the repl to be internal to a package I wonder? @dnlup perhaps you can share the sort of use case you have in mind for using self resolution from the repl? I could certainly get behind supporting this though - and yes it would be doing something like |
Thanks @guybedford for the quick answer.
Sounds good.
I would think so, that is how I am making tests right now.
As of now, it is just something that I think it could be done to have more feature parity with |
Is this done? Can I still help? :) |
Load self referential modules from the repl and using the preload flag `-r`. In both cases the base path used for resolution is the current `process.cwd()`. Refs: * nodejs#31595
Load self referential modules from the repl and using the preload flag `-r`. In both cases the base path used for resolution is the current `process.cwd()`. Also fixes an internal cycle bug in the REPL exports resolution. PR-URL: #32261 Fixes: #31595 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]>
Load self referential modules from the repl and using the preload flag `-r`. In both cases the base path used for resolution is the current `process.cwd()`. Also fixes an internal cycle bug in the REPL exports resolution. PR-URL: nodejs#32261 Fixes: nodejs#31595 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]>
Load self referential modules from the repl and using the preload flag `-r`. In both cases the base path used for resolution is the current `process.cwd()`. Also fixes an internal cycle bug in the REPL exports resolution. PR-URL: #32261 Backport-PR-URL: #35385 Fixes: #31595 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]>
If you attempt to
require('package-name')
using v13.7.0 in the repl it will fail with a 'MODULE_NOT_FOUND' error.The text was updated successfully, but these errors were encountered: