nx: `nx migrate latest` fails on yarn 2
Current Behavior
When running YARN_NODE_LINKER="node-modules" yarn nx migrate latest in a yarn 2 nx workspace, the process ends with Command failed: yarn add @nrwl/workspace@latest.
Expected Behavior
The workspace should be migrated to the latest version of nx
Steps to Reproduce
- Run
npm install -g yarn - Clone https://github.com/bryanforbes/nx-migrate-problem
- Run
yarnin the project - Run
YARN_NODE_LINKER="node-modules" yarn nx migrate latest
Explanation for failure
After creating the temporary directory for tao, tao migrate latest is run from that environment. This command creates a new temporary directory and attempts to run yarn add @nrwl/workspace@latest which fails because no package.json exists. In the repo I linked above, I added a script called tao-yarn-add which emulates this failure by running yarn tao-yarn-add. This must be run via yarn in order to emulate calling yarn add and getting the yarn 2 engine. I’ve also added a script to package.json called tao-yarn-add-fixed that adds a package.json to the empty directory before calling yarn add and this fixes the issue. Again, this script must be run with yarn tao-yarn-add-fixed.
Failure Logs
❯ YARN_NODE_LINKER="node-modules" yarn nx migrate latest
Fetching meta data about packages.
It may take a few minutes.
Fetching @nrwl/workspace@latest
ERROR The migrate command failed.
Command failed: yarn add @nrwl/workspace@latest
/Users/bryan/Projects/ng12-test/node_modules/yargs/build/lib/yargs.js:1132
throw err;
^
Error: Command failed: /var/folders/3k/v_hqdqq57l38tll9dwv0sgl80000gn/T/tmp-36776-kG6GoQPMMs7X/node_modules/.bin/tao migrate latest
at checkExecSyncError (node:child_process:707:11)
at Object.execSync (node:child_process:744:15)
at Object.handler (/Users/bryan/Projects/ng12-test/node_modules/@nrwl/workspace/src/command-line/nx-commands.js:90:25)
at Object.runCommand (/Users/bryan/Projects/ng12-test/node_modules/yargs/build/lib/command.js:196:48)
at Object.parseArgs [as _parseArgs] (/Users/bryan/Projects/ng12-test/node_modules/yargs/build/lib/yargs.js:1043:55)
at Object.get [as argv] (/Users/bryan/Projects/ng12-test/node_modules/yargs/build/lib/yargs.js:986:25)
at Object.initLocal (/Users/bryan/Projects/ng12-test/node_modules/@nrwl/cli/lib/init-local.js:26:79)
at Object.<anonymous> (/Users/bryan/Projects/ng12-test/node_modules/@nrwl/cli/bin/nx.js:43:18)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10) {
status: 1,
signal: null,
output: [ null, null, null ],
pid: 36778,
stdout: null,
stderr: null
}
Environment
Node : 16.1.0 OS : darwin x64 yarn : 2.4.1
nx : Not Found @nrwl/angular : 12.2.0 @nrwl/cli : 12.2.0 @nrwl/cypress : 12.2.0 @nrwl/devkit : 12.2.0 @nrwl/eslint-plugin-nx : 12.2.0 @nrwl/express : Not Found @nrwl/jest : 12.2.0 @nrwl/linter : 12.2.0 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 12.2.0 @nrwl/web : Not Found @nrwl/workspace : 12.2.0 @nrwl/storybook : Not Found @nrwl/gatsby : Not Found typescript : 4.1.5
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 18
- Comments: 17 (5 by maintainers)
@fatihdogmus I encountered the same error and it turned out to be the Angular CLI not supporting my installed version of Node (v16, see issue: https://github.com/angular/angular-cli/issues/20796 ). Running
nx migrate latestwith Node v14 resolved it for me.Here’s a recipe that worked for me:
First, MAKE SURE YOU DON’T HAVE a “.npmrc” file in your repo, otherwise, it won’t work.
Like so:
(provided the patch above is saved under “patches/nx-tao-patch.patch” in the repo)
AND
Works for me!
@luejerry yes! that was exactly the reason! I downgraded the version to 14.17.0 and it worked. Thx a lot
For what its worth, using
NX_MIGRATE_USE_LOCAL=truevariable helped use the local version of nx for this. This may help you unblock until the next error.EDIT: I also had to unplug @nrwl/tao and modify it to get it to work - modify
migrate.js(from the error message) to createpackage.json(content:{name:"temp"}) in the temp directory and I was able to migrate to next.I also removed
unplugmetadata from my mainpackage.jsonand run yarn again and it all worked out.Y’all might be interested in feat(core): implement Yarn v3
Here is how I am using Yarn v3 successfully.
Start with
yarn installusing Yarn v1Then run
yarn set version berryand follow that up withyarn set version 3.x(becauseberryhas a bug)Addd
nodeLinker: node-modulesto.yarnrc.ymlRun
yarn installand update your.gitignorewithThen commit.
I am having no issues with Yarn v3 and updating Nx 👯
Crack a beer.
For the record, the reproduction repo still fails with node 14.17.0.
Although my repo is not using yarn 2 workspaces, just regular yarn, I get the a similar error as above. It is just a toy project, but we will be using nx and angular in a project so encountering this problem could be a problem in the future.
Eror message:
Enviorenment: OS: Windows 10 Enterprise Version 20H2 Yarn: V1.2210 Node.js: v15.6.0
Depndencies nx : Not Found @nrwl/angular : 12.0.6 @nrwl/cli : 12.0.6 @nrwl/cypress : 12.0.6 @nrwl/devkit : 12.0.6 @nrwl/eslint-plugin-nx : 12.0.6 @nrwl/express : Not Found @nrwl/jest : 12.0.6 @nrwl/linter : 12.0.6 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 12.0.6 @nrwl/web : Not Found @nrwl/workspace : 12.0.6 @nrwl/storybook : Not Found @nrwl/gatsby : Not Found typescript : 4.1.5
I think this particular issue has been fixed, since we now create package.json for any folder that receives packages temporarily as it is required to obey .npmrc.
There may still be things broken w/ yarn 2 and pnp, those are tracked via #2386.
I’m going to close this out in favor of that issue. I can’t provide any updates as to yarn 2 / pnp support, but it is something that we are aware of.