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?]: Using imports feature causes Yarn PnP to crash #5187

Closed
1 task
wojtekmaj opened this issue Jan 11, 2023 · 4 comments
Closed
1 task

[Bug?]: Using imports feature causes Yarn PnP to crash #5187

wojtekmaj opened this issue Jan 11, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@wojtekmaj
Copy link
Contributor

wojtekmaj commented Jan 11, 2023

Self-service

  • I'd be willing to implement a fix

Describe the bug

When running chalk@^5.2.0 in Yarn PnP environment (in my case, indirectly, by running yarn dlx serve instead of npx serve, the following error is thrown:

/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-f5b08830/dlx-706/.pnp.cjs:9364
  return Object.defineProperties(new Error(message), {
                                 ^

Error: chalk tried to access #ansi-styles, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: #ansi-styles (via "#ansi-styles/package.json")
Required by: chalk@npm:5.0.1 (via /Users/wmaj/.yarn/berry/cache/chalk-npm-5.0.1-6afcb94227-8.zip/node_modules/chalk/source/index.js)

    at makeError (/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-f5b08830/dlx-706/.pnp.cjs:9364:34)
    at resolveToUnqualified (/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-f5b08830/dlx-706/.pnp.cjs:10283:21)
    at Object.resolveToUnqualified (/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-f5b08830/dlx-706/.pnp.cjs:10427:26)
    at resolve$1 (file:///private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-f5b08830/dlx-706/.pnp.loader.mjs:224:31)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.12.1

This is directly related to chalk/chalk@04fdbd6 in which dependencies were bundled and imports feature was leveraged.

To reproduce

await expect(yarn(`dlx`, `serve`)).rejects.not.toThrow();

Environment

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 18.12.1 - /private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-a3797145/node
    Yarn: 3.3.0 - /private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-a3797145/yarn
    npm: 8.19.2 - /usr/local/bin/npm

Additional context

This was also raised as chalk/chalk#583.

@wojtekmaj wojtekmaj added the bug Something isn't working label Jan 11, 2023
@wojtekmaj wojtekmaj changed the title [Bug?]: Dependencies defined in imports causes Yarn PnP to crash [Bug?]: Using imports feature causes Yarn PnP to crash Jan 11, 2023
@arcanis
Copy link
Member

arcanis commented Jan 11, 2023

Should be solved by #4862, please try the RCs

@arcanis arcanis closed this as completed Jan 11, 2023
@wojtekmaj
Copy link
Contributor Author

wojtekmaj commented Jan 11, 2023

@arcanis Nope :(

wmaj@MacBook-Pro home-page % corepack prepare yarn@canary --activate
Preparing yarn@canary for immediate activation...
wmaj@MacBook-Pro home-page % yarn -v                                
4.0.0-rc.35
wmaj@MacBook-Pro home-page % yarn dlx serve                         
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 2s 689ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 2s 820ms

/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-83d97c82/dlx-2819/.pnp.cjs:9364
  return Object.defineProperties(new Error(message), {
                                 ^

Error: chalk tried to access #ansi-styles, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: #ansi-styles (via "#ansi-styles/package.json")
Required by: chalk@npm:5.0.1 (via /Users/wmaj/.yarn/berry/cache/chalk-npm-5.0.1-6afcb94227-8.zip/node_modules/chalk/source/index.js)

    at makeError (/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-83d97c82/dlx-2819/.pnp.cjs:9364:34)
    at resolveToUnqualified (/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-83d97c82/dlx-2819/.pnp.cjs:10283:21)
    at Object.resolveToUnqualified (/private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-83d97c82/dlx-2819/.pnp.cjs:10427:26)
    at resolve$1 (file:///private/var/folders/wg/cztxqmdj6h94ht8783cym75c0000gp/T/xfs-83d97c82/dlx-2819/.pnp.loader.mjs:224:31)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
    at link (node:internal/modules/esm/module_job:75:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.12.1

@merceyz
Copy link
Member

merceyz commented Jan 11, 2023

You're running into nodejs/corepack#202, you'll need to update Corepack.

Should be solved by #4862, please try the RCs

It was backported to v3.

@wojtekmaj
Copy link
Contributor Author

wojtekmaj commented Jan 11, 2023

You are correct! I was hitting the issue with Corepack 0.14.2 + Yarn 3.3.1/4.0.0-rc.35, but NOT with Corepack 0.15.3 + Yarn 3.3.1/4.0.0-rc.35.

Thanks!

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

4 participants
@arcanis @merceyz @wojtekmaj and others