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?]: Cannot find module 'esbuild' imported from ../ #5241

Open
1 task
dalisoft opened this issue Feb 2, 2023 · 9 comments
Open
1 task

[Bug?]: Cannot find module 'esbuild' imported from ../ #5241

dalisoft opened this issue Feb 2, 2023 · 9 comments
Labels
bug Something isn't working documentation This issue or pull request is about the documentation upholded Real issues without formal reproduction

Comments

@dalisoft
Copy link

dalisoft commented Feb 2, 2023

Self-service

  • I'd be willing to implement a fix

Describe the bug

pnpm-esbuild/frontend on  master via ⬢ v19.5.0 took 2s 
❯ node -r ./.pnp.cjs ./scripts/build.mjs
node:internal/process/esm_loader:78
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'esbuild' imported from /Users/dalisoft/Desktop/bug/pnpm-esbuild/frontend/scripts/build.mjs
Did you mean to import esbuild/frontend/.yarn/unplugged/esbuild-npm-0.17.5-ba581df653/node_modules/esbuild/lib/main.js?
    at new NodeError (node:internal/errors:399:5)
    at packageResolve (node:internal/modules/esm/resolve:794:9)
    at moduleResolve (node:internal/modules/esm/resolve:843:20)
    at defaultResolve (node:internal/modules/esm/resolve:1058:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:837:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:418:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v19.5.0
pnpm-esbuild/frontend on  master via ⬢ v19.5.0 
❯ yarn why esbuild
└─ frontend@workspace:.
   └─ esbuild@npm:0.17.5 (via npm:^0.17.5)

To reproduce

git clone git@github.com:dalisoft/pnpm-esbuild.git
cd pnpm-esbuild
cd frontend
yarn set version stable
yarn
node -r ./.pnp.cjs ./scripts/build.mjs // or yarn node scripts/build.mjs

Environment

System:
    OS: macOS 12.6.3
    CPU: (8) arm64 Apple M1
Binaries:
    Node: 19.5.0 - /private/var/folders/kj/92wfmyss40g5lzxfmy9czwwh0000gn/T/xfs-12b8fbd2/node
    Yarn: 3.4.1 - /private/var/folders/kj/92wfmyss40g5lzxfmy9czwwh0000gn/T/xfs-12b8fbd2/yarn
    npm: 9.3.1 - /opt/homebrew/bin/npm

Additional context

No response

@dalisoft dalisoft added the bug Something isn't working label Feb 2, 2023
@merceyz
Copy link
Member

merceyz commented Feb 2, 2023

Seems we've forgotten to update the documentation; when using ESM you need to register the loader as well.

node -r ./.pnp.cjs --loader ./.pnp.loader.mjs

@merceyz merceyz closed this as completed Feb 2, 2023
@merceyz merceyz reopened this Feb 2, 2023
@merceyz merceyz added documentation This issue or pull request is about the documentation upholded Real issues without formal reproduction labels Feb 2, 2023
@dalisoft
Copy link
Author

dalisoft commented Feb 2, 2023

@merceyz There no file .pnp.loader.mjs, where i can get this file? Thank you

@merceyz
Copy link
Member

merceyz commented Feb 2, 2023

yarn config set pnpEnableEsmLoader true

https://yarnpkg.com/configuration/yarnrc#pnpEnableEsmLoader

@dalisoft
Copy link
Author

dalisoft commented Feb 2, 2023

thank you, oh, sorry, yep, i able to fix by two way:

  • Add {"type": "module"} into package.json then run yarn install [THIS WORKS BETTER]
  • and/or setting pnpEnableEsmLoader: true in .yarnrc.yml (now whitelisted in repo)

Using yarn node SCRIPT works much stable than node -r

@dalisoft dalisoft closed this as completed Feb 2, 2023
@merceyz
Copy link
Member

merceyz commented Feb 2, 2023

I'll keep this open since we need to update the documentation.

@merceyz merceyz reopened this Feb 2, 2023
@dalisoft
Copy link
Author

dalisoft commented Feb 2, 2023

@merceyz #5241 (comment) did not help. Only adding {type: module} helped

@merceyz
Copy link
Member

merceyz commented Feb 2, 2023

You also need to run an install after setting that config in your project.

@dalisoft
Copy link
Author

dalisoft commented Feb 3, 2023

Yes, i know and still not worked as expected. But finally solution I'm did find, that's has been my goal.
Thank you for help and useful links

@mondo192
Copy link

I also encountered this bug. Running the below commands was the only thing that worked for me. YMMV.

yarn config set pnpEnableEsmLoader true
yarn install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation This issue or pull request is about the documentation upholded Real issues without formal reproduction
Projects
None yet
Development

No branches or pull requests

3 participants