Open milesrichardson opened 11 months ago
UPDATE: I think the bug is in corepack
.
I upgraded Node from 20.9.0
to the latest stable version 20.10.0
.
4.0.2
stableI upgraded yarn
from 4.0.1
to the latest stable 4.0.2
version with yarn set version stable
. In this case, the bug is NOT fixed:
β― yarn dlx -q envinfo --preset jest
System:
OS: macOS 13.5
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Binaries:
Node: 20.10.0 - /private/var/folders/np/djbv9lnn5wd62yrs60zxh_p40000gn/T/xfs-414ff96f/node
Yarn: 4.0.2 - /private/var/folders/np/djbv9lnn5wd62yrs60zxh_p40000gn/T/xfs-414ff96f/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
β― yarn constraints
Type Error: A dynamic import callback was not specified.
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:182:9)
at /Users/myusername/path-to/my-project/yarn.config.cjs:10:5
at new Promise (<anonymous>)
at loadIsExactVersion (/Users/myusername/path-to/my-project/yarn.config.cjs:9:10)
at Object.constraints (/Users/myusername/path-to/my-project/yarn.config.cjs:22:35)
at wC.process (/Users/myusername/.cache/node/corepack/yarn/4.0.2/yarn.js:524:74675)
at async p0.execute (/Users/myusername/.cache/node/corepack/yarn/4.0.2/yarn.js:526:1996)
at async p0.validateAndExecute (/Users/myusername/.cache/node/corepack/yarn/4.0.2/yarn.js:94:787)
at async as.run (/Users/myusername/.cache/node/corepack/yarn/4.0.2/yarn.js:98:3250)
at async oPt (/Users/myusername/.cache/node/corepack/yarn/4.0.2/yarn.js:734:11269)
master
, but is it?The bug appears to be fixed after installing the version of yarn from master
using yarn set version from sources
.
However, I believe this is an illusion, indicating that the real bug is in corepack
, which is not used when installing Yarn from source, as noted in the docs:
Unlike the stable and canary channels, the yarn set version from sources command can't leverage Corepack and will need to store the Yarn binary inside the .yarn/releases folder and reference it from your project's .yarnrc.yml file.
β― yarn dlx -q envinfo --preset jest
System:
OS: macOS 13.5
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Binaries:
Node: 20.10.0 - /private/var/folders/np/djbv9lnn5wd62yrs60zxh_p40000gn/T/xfs-aca9279f/node
Yarn: 4.0.2-git.20231115.hash-017b94a - /private/var/folders/np/djbv9lnn5wd62yrs60zxh_p40000gn/T/xfs-aca9279f/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
β― yarn constraints
ββ myproject@workspace:.
ββ The script ran successfully, at least
Hey! Thanks for all your work on Yarn 4. :) I love it so far, and writing constraints in JS is a nice change. I've encountered a bug, but there's a workaround...
Self-service
Describe the bug
Running
yarn constraints
throws a fatal error ("A dynamic import callback was not specified
") whenyarn.config.cjs
attempts toimport()
code from an ECMAScript Module. This is a bug, because dynamicimport()
should be available in all CommonJS modules (in fact, when you try torequire()
from an ESM, the error message even tells you to switch toimport()
).However, the script executes successfully when executed with
DISABLE_V8_COMPILE_CACHE=1 yarn constraints
. This indicates the bug is likely in thev8-compile-cache
package (possibly the one referenced in this open issue from 2020). However, I have not investigated the root cause. For me, the workaround is fine, and I simply added a script in mypackage.json
to set the variable:"scripts": { "check-constraints": "DISABLE_V8_COMPILE_CACHE=1 yarn constraints" }
.Possibly related: I am using the
node-modules
linker.To reproduce
1. Create a new Yarn project with
node-modules
linkerFirst, create a new Yarn project. I've noticed this bug with the
node-modules
linker. I haven't attempted to replicate it with PnP. This is my.yarnrc.yml
:2. Install the
is-exact-version
packageThe package I am attempting to import is
is-exact-version
, which is installed in thedependencies
of my root workspace. You can reproduce it by installing the same version I have:This is what the main export of that package looks like (note that it's using
import
statements):3. Sanity check:
require()
fails, as expectedPut this into
yarn.config.cjs
and runyarn constraints
:As expected, we get an error telling us to
import
instead:4. Reproduce the bug:
import()
failsTry the simplest possible dynamic
import()
:This fails with error:
4. Reproduce the workaround
Setting
DISABLE_V8_COMPILE_CACHE=1
resolves the issue and the script runs successfully:Appendix: Potential fix that does not work
Given the error about the unresolved callback, I tried wrapping the import safely. This makes no difference - it produces the same error:
Environment
Additional context
As mentioned, I am using the
node-modules
linker.The only reason I noticed that
DISABLE_V8_COMPILE_CACHE=1
fixed the bug is because when I was switching back and forth between attempts to fix the script, I would sometimes encounter a different error, "invalid host defined options
." Googling that led me tov8-compile-cache
. There are some recent issues with similar errors in other projects, e.g. https://github.com/pyodide/pyodide/issues/4267 and https://github.com/prettier/prettier-vscode/issues/3114 (Then I asked ChatGPT if I could opt out of v8-compile-cache, and it told me I could setDISABLE_V8_COMPILE_CACHE=1
, which sounded so convenient I thought it was hallucinating, but it worked!)