Skip to content
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

REPL throws on requiring a package with exports field #34521

Closed
JLHwung opened this issue Jul 26, 2020 · 4 comments
Closed

REPL throws on requiring a package with exports field #34521

JLHwung opened this issue Jul 26, 2020 · 4 comments

Comments

@JLHwung
Copy link

JLHwung commented Jul 26, 2020

  • Version: v14.6.0
  • Platform: Darwin Kernel Version 19.6.0

What steps will reproduce the bug?

(Credits to @proteriax)

mkdir test && cd test
yarn init --yes
yarn add @babel/helper-validator-identifier
node

Welcome to Node.js v14.6.0.
Type ".help" for more information.
> require('@babel/helper-validator-identifier')

How often does it reproduce? Is there a required condition?

Must reproduce

What is the expected behavior?

It should require the module.

What do you see instead?

Uncaught:
TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "/test/node_modules/@babel/helper-validator-identifier/lib/index.js" must not include encoded "/" or "\" characters imported from /test/node_modules/@babel/helper-validator-identifier/
    at resolveExportsTarget (internal/modules/cjs/loader.js:564:15)
    at applyExports (internal/modules/cjs/loader.js:469:14)
    at resolveExports (internal/modules/cjs/loader.js:522:23)
    at Function.Module._findPath (internal/modules/cjs/loader.js:654:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1052:27)
    at Function.Module._load (internal/modules/cjs/loader.js:911:27)
    at Module.require (internal/modules/cjs/loader.js:1125:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at repl:1:1
    at Script.runInThisContext (vm.js:132:18) {
  code: 'ERR_INVALID_MODULE_SPECIFIER'
}

One can verify the package is working properly:

node -e "require('@babel/helper-validator-identifier')"

REPL does not throw if you remove exports from package.json, though this is unfavored.

Additional information

Context: babel/babel#11878

Maybe related: #32935 But IMO adding exports should not break the ability of requiring a commonjs module in REPL.

/cc @guybedford

@alex-kinokon
Copy link

For the record, this is also reproducible if the require is inside a .js file.

@ZYSzys
Copy link
Member

ZYSzys commented Aug 3, 2020

Look like this was fixed by #32261.

@alex-kinokon
Copy link

I can confirm it’s fixed with v15.0.0-nightly2020080584b35b2867.

@JLHwung
Copy link
Author

JLHwung commented Aug 5, 2020

Can confirm that it's fixed in v14.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants