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

[Bug] Can't import anything in pnp mode #1698

Closed
1 task
wojtekmaj opened this issue Aug 12, 2020 · 2 comments
Closed
1 task

[Bug] Can't import anything in pnp mode #1698

wojtekmaj opened this issue Aug 12, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@wojtekmaj
Copy link
Contributor

wojtekmaj commented Aug 12, 2020

  • I'd be willing to implement a fix

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

yarn set version latest
yarn init

+

package.json:

{
  "name": "berry-import-bug",
  "type": "module",
  "scripts": {
    "fail1": "node index.js",
    "fail2": "node --experimental-modules --es-module-specifier-resolution=node index.js",
    "fail3": "yarn node index.js",
    "fail4": "yarn node --experimental-modules --es-module-specifier-resolution=node index.js",
    "fail5": "node -r ./.pnp.cjs index.js",
    "fail6": "node -r ./.pnp.cjs --experimental-modules --es-module-specifier-resolution=node index.js"
  },
  "dependencies": {
    "lodash": "^4.17.19"
  }
}

index.js:

import lodash from 'lodash';

Running ANY of the scripts above will fail.

  • 1, 3 and 5 will fall because of ERR_REQUIRE_ESM
  • 2, 4 and 6 will correctly load index.js, but will fail to import lodash (or anything else for that matter):
berry-express-bug % yarn fail2
internal/modules/run_main.js:54
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'lodash' imported from /berry-import-bug/index.js
Did you mean to import lodash-npm-4.17.19-fa87a8e838-ff2b7a95f0.zip/node_modules/lodash/lodash.js?
    at packageResolve (internal/modules/esm/resolve.js:594:9)
    at moduleResolve (internal/modules/esm/resolve.js:633:14)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:726:11)
    at Loader.resolve (internal/modules/esm/loader.js:82:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:226:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:51:40)
    at link (internal/modules/esm/module_job.js:50:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Environment if relevant (please complete the following information):

  • OS: [e.g. OSX, Linux, Windows, ...] macOS Big Sur
  • Node version [e.g. 8.15.0, 10.15.1, ...] 14.5.0
  • Yarn version [e.g. 2.0.0-rc1, ...] 2.1.1
@wojtekmaj wojtekmaj added the bug Something isn't working label Aug 12, 2020
@merceyz
Copy link
Member

merceyz commented Aug 12, 2020

ESM support is tracked in #638

@merceyz merceyz closed this as completed Aug 12, 2020
@wojtekmaj
Copy link
Contributor Author

Then shouldn't running yarn fail in ESM with a clear message that it isn't supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants