Skip to content

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

@wojtekmaj

Description

@wojtekmaj

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions