Closed
Description
Self-service
- I'd be willing to implement a fix
Describe the bug
When trying to write typed constraints as shown in the documentation I get an error message. This is behavior is consistent in our mono-repo project as well as newly created empty project.
ulrik@besk:~/github/yarn-test$ yarn add @yarnpkg/types
➤ YN0000: · Yarn 4.0.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @yarnpkg/types@npm:4.0.0, tslib@npm:2.6.2
➤ YN0000: └ Completed in 0s 654ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 2 packages were added to the project (+ 94.47 KiB).
➤ YN0000: └ Completed in 0s 835ms
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 1s 521ms
ulrik@besk:~/github/yarn-test$ yarn constraints
Internal Error: Cannot find module '@yarnpkg/types'
Require stack:
- /home/ulrik/github/yarn-test/yarn.config.cjs
- /home/ulrik/github/yarn-test/.yarn/releases/yarn-berry.cjs
Require stack:
- /home/ulrik/github/yarn-test/yarn.config.cjs
- /home/ulrik/github/yarn-test/.yarn/releases/yarn-berry.cjs
at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
at Module._load (node:internal/modules/cjs/loader:901:27)
at Module.require (node:internal/modules/cjs/loader:1115:19)
at require (node:internal/modules/helpers:130:18)
at Object.<anonymous> (/home/ulrik/github/yarn-test/yarn.config.cjs:1:26)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at Module.require (node:internal/modules/cjs/loader:1115:19)
ulrik@besk:~/github/yarn-test$ ls
package.json yarn.config.cjs yarn.lock
ulrik@besk:~/github/yarn-test$ cat package.json
{
"name": "yarn-test",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@yarnpkg/types": "^4.0.0"
}
}
ulrik@besk:~/github/yarn-test$ cat yarn.config.cjs
const { defineConfig } = require('@yarnpkg/types');
module.exports = defineConfig({
async constraints({Yarn}) {
// `Yarn` is now well-typed ✨
},
});
To reproduce
yarn init -y
yarn set version berry
echo "const { defineConfig } = require('@yarnpkg/types');" > yarn.config.cjs
yarn add @yarnpkg/types
yarn constraints
Environment
System:
OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
CPU: (32) x64 AMD Ryzen 9 3950X 16-Core Processor
Binaries:
Node: 20.8.1 - /tmp/xfs-b30aa552/node
Yarn: 4.0.0 - /tmp/xfs-b30aa552/yarn
npm: 10.1.0 - /usr/local/bin/npm
Additional context
No response