Skip to content

[Bug?]: Dynamic require is not supported after installing yarn #6773

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

Open
1 task
smeng9 opened this issue Apr 23, 2025 · 0 comments
Open
1 task

[Bug?]: Dynamic require is not supported after installing yarn #6773

smeng9 opened this issue Apr 23, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@smeng9
Copy link
Contributor

smeng9 commented Apr 23, 2025

Self-service

  • I'd be willing to implement a fix

Describe the bug

I tried to use the COREPACK_HOME to install the yarn package manager to a local folder inside my repo so I can commit the package manager in an air-gapped environment. Then next time I no longer need to download the package manager with that specific version from internet.

I noticed the once I set COREPACK_HOME to . and if my package.json under that same directory contains "type": "module", the yarn will throw error.

To reproduce

Create a following package.json

{
    "name": "asdf",
    "private": true,
    "version": "2.0.116",
    "type": "module",
    "dependencies": {
        "react": "^19.1.0"
    },
    "packageManager": "[email protected]+sha512.f95ce356460e05be48d66401c1ae64ef84d163dd689964962c6888a9810865e39097a5e9de748876c2e0bf89b232d583c33982773e9903ae7a76257270986538"
}

Then in the same folder run the following command

export COREPACK_HOME=$(pwd)
corepack prepare yarn --activate

Run the yarn command and the following error shows up

Error: Dynamic require of "util" is not supported
at file:///home/node/v1/yarn/4.9.1/yarn.js:4:394
at file:///home/node/v1/yarn/4.9.1/yarn.js:4:3568
at file:///home/node/v1/yarn/4.9.1/yarn.js:4:474
at file:///home/node/v1/yarn/4.9.1/yarn.js:9:46383
at file:///home/node/v1/yarn/4.9.1/yarn.js:4:474
at file:///home/node/v1/yarn/4.9.1/yarn.js:413:15664
at file:///home/node/v1/yarn/4.9.1/yarn.js:759:448
at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
at async onImport.tracePromise.proto (node:internal/modules/esm/loader:644:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:98:5)

Solution: If dynamic require is not supported, it should at least try a dynamic import as a fallback solution.

Environment

Note: I cannot run yarn from my if I installed the yarn to a local directory inside my repo. 


  System:
    OS: Linux 6.4 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (8) arm64 unknown
  Binaries:
    Node: 23.11.0 - /tmp/xfs-8ee5826b/node
    Yarn: 4.9.1 - /tmp/xfs-8ee5826b/yarn
    npm: 10.9.2 - /usr/local/bin/npm

Additional context

No response

@smeng9 smeng9 added the bug Something isn't working label Apr 23, 2025
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

1 participant