Skip to content
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

nx migrate latest fails on yarn 2 #5672

Closed
bryanforbes opened this issue May 14, 2021 · 17 comments
Closed

nx migrate latest fails on yarn 2 #5672

bryanforbes opened this issue May 14, 2021 · 17 comments
Labels

Comments

@bryanforbes
Copy link

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

  1. Run npm install -g yarn
  2. Clone https://github.com/bryanforbes/nx-migrate-problem
  3. Run yarn in the project
  4. 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

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label May 14, 2021
@fatihdogmus
Copy link

fatihdogmus commented May 21, 2021

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:

> yarn nx migrate latest
yarn run v1.22.10
$ nx migrate latest
C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\yargs\build\lib\yargs.js:1132
                throw err;
                ^

Error: Command failed: yarn
    at checkExecSyncError (node:child_process:682:11)
    at Object.execSync (node:child_process:719:15)
    at taoPath (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\@nrwl\workspace\src\command-line\nx-commands.js:312:21)
    at Object.handler (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\@nrwl\workspace\src\command-line\nx-commands.js:86:19)
    at Object.runCommand (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\yargs\build\lib\command.js:196:48)
    at Object.parseArgs [as _parseArgs] (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\yargs\build\lib\yargs.js:1043:55)
    at Object.get [as argv] (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\yargs\build\lib\yargs.js:986:25)
    at Object.initLocal (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\@nrwl\cli\lib\init-local.js:24:13)
    at Object.<anonymous> (C:\Users\fatih.dogmus\IdeaProjects\angular-learning\node_modules\@nrwl\cli\bin\nx.js:43:18)
    at Module._compile (node:internal/modules/cjs/loader:1108:14) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 26920,
  stdout: null,
  stderr: null
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

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

@nemonemi
Copy link

nemonemi commented May 24, 2021

With Yarn 2 here, same problem different message:
yarn nx migrate latest

 yarn nx migrate latest
The system cannot find the path specified.
C:\www\path_to_project\node_modules\yargs\build\lib\yargs.js:1132
                throw err;
                ^

Error: Command failed: C:\Users\***\AppData\Local\Temp\tmp-29160-kCrQrVmtn2Bd\node_modules\.bin\tao migrate latest
    at checkExecSyncError (child_process.js:616:11)
    at Object.execSync (child_process.js:652:15)
    at Object.handler (C:\www\path_to_project\node_modules\@nrwl\workspace\src\command-line\nx-commands.js:90:25)
    at Object.runCommand (C:\www\path_to_project\node_modules\yargs\build\lib\command.js:196:48)
    at Object.parseArgs [as _parseArgs] (C:\www\path_to_project\node_modules\yargs\build\lib\yargs.js:1043:55)
    at Object.get [as argv] (C:\www\path_to_project\node_modules\yargs\build\lib\yargs.js:986:25)
    at Object.initLocal (C:\www\path_to_project\node_modules\@nrwl\cli\lib\init-local.js:26:79)
    at Object.<anonymous> (C:\www\path_to_project\node_modules\@nrwl\cli\bin\nx.js:43:18)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 32980,
  stdout: null,
  stderr: null
}

nx report

 Node : 14.16.0
  OS   : win32 x64
  yarn : 2.4.1

  nx : Not Found
  @nrwl/angular : Not Found
  @nrwl/cli : 12.1.1
  @nrwl/cypress : 12.1.1
  @nrwl/devkit : 12.1.1
  @nrwl/eslint-plugin-nx : 12.1.1
  @nrwl/express : Not Found
  @nrwl/jest : 12.1.1
  @nrwl/linter : 12.1.1
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : 12.1.1
  @nrwl/schematics : 8.12.11
  @nrwl/tao : 12.1.1
  @nrwl/web : 12.1.1
  @nrwl/workspace : 12.1.1
  @nrwl/storybook : 12.1.1
  @nrwl/gatsby : Not Found
  typescript : 4.2.4

@luejerry
Copy link

luejerry commented May 27, 2021

@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: angular/angular-cli#20796 ). Running nx migrate latest with Node v14 resolved it for me.

@fatihdogmus
Copy link

@luejerry yes! that was exactly the reason! I downgraded the version to 14.17.0 and it worked. Thx a lot

@bryanforbes
Copy link
Author

Yarn 2 ignores the engine requirements, so Angular 12 should be fine on Yarn 2 + Node 16 and won't stop the install

@akryvasheyeu
Copy link

It works with node v14, with v16 not, same exception on migration from 12.2.0 to 12.3.5

@bryanforbes
Copy link
Author

For the record, the reproduction repo still fails with node 14.17.0.

@raphzandrade
Copy link

Still having issues with this.

@sushruth
Copy link
Contributor

sushruth commented Sep 7, 2021

For what its worth, using NX_MIGRATE_USE_LOCAL=true variable 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 create package.json (content: {name:"temp"}) in the temp directory and I was able to migrate to next.

I also removed unplug metadata from my main package.json and run yarn again and it all worked out.

@insanicly
Copy link

this is still an issue. I am getting the same error with the below configuration:
yarn nx --version 12.9.0

yarn --version 3.0.2

node --version v14.18.0

@sledorze
Copy link

sledorze commented Nov 9, 2021

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.

  1. Applying this patch (which creates the temp file in the repo):
diff --git a/src/commands/migrate.js b/src/commands/migrate.js
index fe11e0558eeede06642d21f307ee18c2ca0d24d5..a1e4874846bc9e4a67fd18b9db5021de243bd751 100644
--- a/src/commands/migrate.js
+++ b/src/commands/migrate.js
@@ -317,7 +317,7 @@ function createFetcher() {
     return function f(packageName, packageVersion) {
         return tslib_1.__awaiter(this, void 0, void 0, function* () {
             if (!cache[`${packageName}-${packageVersion}`]) {
-                const dir = tmp_1.dirSync().name;
+                const dir = tmp_1.dirSync({ tmpdir:process.cwd() }).name;
                 const npmrc = checkForNPMRC();
                 if (npmrc) {
                     // Creating a package.json is needed for .npmrc to resolve

Like so:

"@nrwl/tao": "patch:@nrwl/tao@13.1.3#patches/nx-tao-patch.patch",

(provided the patch above is saved under "patches/nx-tao-patch.patch" in the repo)

AND

  1. call the migration like this (thanks @sushruth ):
NX_MIGRATE_USE_LOCAL=true yarn nx migrate latest

Works for me!

@benpsnyder
Copy link
Contributor

Here is how I am using Yarn v3 successfully.

Start with yarn install using Yarn v1

Then run yarn set version berry and follow that up with yarn set version 3.x (because berry has a bug)

Addd nodeLinker: node-modules to .yarnrc.yml

Run yarn install and update your .gitignore with

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

Then commit.

I am having no issues with Yarn v3 and updating Nx 👯

Crack a beer.

@benpsnyder
Copy link
Contributor

Y'all might be interested in feat(core): implement Yarn v3

@devinshoemaker
Copy link
Contributor

Can confirm this issue using Yarn 1 with Node 16. Switching to Node 14 for the migration seems to work.

@nemonemi
Copy link

One use case to contribute is if you run it with yarn nx migrate... it fails, but with global nx migrate... it works.

@AgentEnder
Copy link
Member

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.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests