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

Application build failing after upgrade to 15.4.2 #14106

Closed
Blizard opened this issue Jan 3, 2023 · 9 comments · Fixed by #14204
Closed

Application build failing after upgrade to 15.4.2 #14106

Blizard opened this issue Jan 3, 2023 · 9 comments · Fixed by #14204
Assignees
Labels

Comments

@Blizard
Copy link

Blizard commented Jan 3, 2023

Current Behavior

Both dynamic/static application build fail with error after upgrade from 15.0.13 to 15.4.2 using nx migrate latest

Expected Behavior

Both dynamic and static build should pass successfully

Github Repo

No response

Steps to Reproduce

  1. For now i could not reproduce the problem in new NX repo

Nx Report

Node : 16.13.2
   OS   : darwin x64
   yarn : 3.2.0
   
   nx : 15.4.2
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.4.2
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.4.2
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.4.2
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.4.2
   @nrwl/js : 15.4.2
   @nrwl/linter : 15.4.2
   @nrwl/nest : Not Found
   @nrwl/next : 15.4.2
   @nrwl/node : Not Found
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.4.2
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.4.2
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : 15.4.2
   @nrwl/webpack : 15.4.2
   @nrwl/workspace : 15.4.2
   @nrwl/vite : 15.4.2
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

> nx run app:build:production

info  - Loaded env from apps/app/.env
info  - Skipping linting
info  - Checking validity of types  
info  - Creating an optimized production build  
info  - Compiled successfully
Warning: You have opted-out of Automatic Static Optimization due to `getInitialProps` in `pages/_app`. This does not opt-out pages with `getStaticProps`
Read more: https://nextjs.org/docs/messages/opt-out-auto-static-optimization

info  - Collecting page data  
Route (pages)                              Size     First Load JS
┌ λ /                                      335 B           326 kB
├   /_app                                  0 B             326 kB
├ λ /404                                   186 B           326 kB
├ λ /...                              1.06 kB         327 kB
├ λ /...                                339 B           326 kB
└ λ /...                                   4.66 kB         331 kB
+ First Load JS shared by all              331 kB
  ├ chunks/framework-66afa89ce7187f6f.js   45.4 kB
  ├ chunks/main-ca9105e8b818c1fc.js        25.7 kB
  ├ chunks/pages/_app-ad0a9e42fc439306.js  252 kB
  ├ chunks/webpack-9cbaf5751fa1a785.js     3.08 kB
  └ css/869f1d99baaa8fef.css               5.09 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)


>  NX   undefined is not iterable (cannot read property Symbol(Symbol.iterator))

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at pruneDependency (.../node_modules/nx/src/lock-file/yarn.js:223:26)
    at .../node_modules/nx/src/lock-file/yarn.js:210:21
    at Array.forEach (<anonymous>)
    at pruneDependencies (.../node_modules/nx/src/lock-file/yarn.js:204:181)
    at pruneYarnLockFile (.../node_modules/nx/src/lock-file/yarn.js:177:32)
    at createLockFile (.../node_modules/nx/src/lock-file/lock-file.js:148:57)
    at .../node_modules/@nrwl/next/src/executors/build/build.impl.js:55:54
    at Generator.next (<anonymous>)
    at fulfilled (.../node_modules/tslib/tslib.js:114:62)
    at runMicrotasks (<anonymous>)


Error: Command failed: nx run app:export
    at checkExecSyncError (node:child_process:826:11)
    at execSync (node:child_process:900:15)
    at createSyncProcess (.../node_modules/nx/src/executors/run-commands/run-commands.impl.js:166:34)
    at .../node_modules/nx/src/executors/run-commands/run-commands.impl.js:113:13
    at Generator.next (<anonymous>)
    at .../node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (.../node_modules/tslib/tslib.js:113:16)
    at runSerially (.../node_modules/nx/src/executors/run-commands/run-commands.impl.js:111:20)
    at .../node_modules/nx/src/executors/run-commands/run-commands.impl.js:52:25 {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 83587,
  stdout: null,
  stderr: null
}

Additional Information

No response

@jaysoo jaysoo added the scope: core core nx functionality label Jan 3, 2023
@hoonoh
Copy link
Contributor

hoonoh commented Jan 4, 2023

This bug seems to be related to versions 15.4.0 and up.
After rolling back to 15.3.3 everyting seems to be fine.

@bojanbass
Copy link

I've got the same issue and after debugging this is what I've found:

The issue is only present in my existing NX monorepo with a ton of other npm dependencies, but with a clean NX repo it works fine. Both use Yarn. After logging problematic line https://github.com/nrwl/nx/blob/master/packages/nx/src/lock-file/yarn.ts#L307-L309, the one that is failing is missing rootVersion property for typescript@patch:typescript dependency.

Failing example:

{
  "[email protected]": {
    "version": "4.9.4",
    "resolution": "typescript@npm:4.9.4",
    "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" },
    "checksum": "e782fb9e0031cb258a80000f6c13530288c6d63f1177ed43f770533fdc15740d271554cdae86701c1dd2c83b082cea808b07e97fd68b38a172a83dbf9e0d0ef9",
    "languageName": "node",
    "linkType": "hard",
    "packageMeta": ["typescript@npm:2 - 4"]
  },
  "[email protected]": {
    "version": "4.8.4",
    "resolution": "typescript@npm:4.8.4",
    "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" },
    "checksum": "3e4f061658e0c8f36c820802fa809e0fd812b85687a9a2f5430bc3d0368e37d1c9605c3ce9b39df9a05af2ece67b1d844f9f6ea8ff42819f13bcb80f85629af0",
    "languageName": "node",
    "linkType": "hard",
    "packageMeta": ["typescript@npm:4.8.4"],
    "rootVersion": true
  }
}

{
  "typescript@patch:[email protected]": {
    "version": "npm%3A4.9.4#~builtin<compat/typescript>::version=4.9.4&hash=701156",
    "resolution": "typescript@patch:typescript@npm%3A4.9.4#~builtin<compat/typescript>::version=4.9.4&hash=701156",
    "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" },
    "checksum": "37f6e2c3c5e2aa5934b85b0fddbf32eeac8b1bacf3a5b51d01946936d03f5377fe86255d4e5a4ae628fd0cd553386355ad362c57f13b4635064400f3e8e05b9d",
    "languageName": "node",
    "linkType": "hard",
    "actualVersion": "4.9.4",
    "packageMeta": [
      "typescript@patch:typescript@2 - 4#~builtin<compat/typescript>"
    ]
  },
  "typescript@patch:[email protected]": {
    "version": "npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=701156",
    "resolution": "typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=701156",
    "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" },
    "checksum": "301459fc3eb3b1a38fe91bf96d98eb55da88a9cb17b4ef80b4d105d620f4d547ba776cc27b44cc2ef58b66eda23fe0a74142feb5e79a6fb99f54fc018a696afa",
    "languageName": "node",
    "linkType": "hard",
    "actualVersion": "4.8.4",
    "packageMeta": [
      "typescript@patch:[email protected]#~builtin<compat/typescript>",
      "typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>"
    ]
  }
}

Working example

{
  "[email protected]": {
    "version": "4.8.4",
    "resolution": "typescript@npm:4.8.4",
    "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" },
    "checksum": "3e4f061658e0c8f36c820802fa809e0fd812b85687a9a2f5430bc3d0368e37d1c9605c3ce9b39df9a05af2ece67b1d844f9f6ea8ff42819f13bcb80f85629af0",
    "languageName": "node",
    "linkType": "hard",
    "packageMeta": ["typescript@npm:~4.8.2"],
    "rootVersion": true
  }
}

{
  "typescript@patch:[email protected]": {
    "version": "npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=701156",
    "resolution": "typescript@patch:typescript@npm%3A4.8.4#~builtin<compat/typescript>::version=4.8.4&hash=701156",
    "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" },
    "checksum": "301459fc3eb3b1a38fe91bf96d98eb55da88a9cb17b4ef80b4d105d620f4d547ba776cc27b44cc2ef58b66eda23fe0a74142feb5e79a6fb99f54fc018a696afa",
    "languageName": "node",
    "linkType": "hard",
    "actualVersion": "4.8.4",
    "packageMeta": [
      "typescript@patch:typescript@~4.8.2#~builtin<compat/typescript>"
    ],
    "rootVersion": true
  }
}

Typescript v4.9.4 was however added because it is a dependency of @commitlint/load in my case, which shouldn't affect building NextJs app with NX, so I this should be an NX related bug, as only typescript v4.8.4 should be loaded in this case.

After removing @commitlint/load from packages, the build was successful, but not a solution.

The only working solution that is acceptable currently is by using yarn resolutions and fix typescript version to v4.8.4 inside package.json:

"resolutions": {
  "@commitlint/load/typescript": "4.8.4"
}

@bojanbass
Copy link

I also wanted to say that upgrading NX has been a slight nightmare lately, because after I found this bug I downgraded NX to v.15.3.3, but later developers on the Windows platform were complaining that it's not possible to start or build and app using a custom NX executor. The error from the output was:

$ nx serve myApp

> NX   Unable to resolve @myOrg/nx-vue:dev-server.

Unable to resolve local plugin with import path @myOrg/nx-vue

So it was failing to reference a local plugin on Windows only. It looks like this was fixed in NX v15.4.0, but then the bug from this ticket appeared.

@jaysoo jaysoo self-assigned this Jan 5, 2023
@jaysoo
Copy link
Member

jaysoo commented Jan 6, 2023

Is someone willing to share their yarn.lock file with me? You can link a gist here or DM it to me https://twitter.com/jay_soo

@jaysoo
Copy link
Member

jaysoo commented Jan 6, 2023

We'll disable the lockfile behavior, and do more testing around it. Should be in the next release. Sorry for the inconvenience.

@jaysoo
Copy link
Member

jaysoo commented Jan 6, 2023

Merged and will be fixed in 14.4.5.

@sushruth
Copy link
Contributor

@jaysoo This is still happening when yarn2+ is used. The problem seems to be that this function -

export function isRootVersion(packageName: string, version: string): boolean {
const fullPath = `${workspaceRoot}/node_modules/${packageName}/package.json`;
if (existsSync(fullPath)) {
const content = readFileSync(fullPath, 'utf-8');
return JSON.parse(content).version === version;
} else {
return false;
}
}

checks for existence of a file that may not exist in yarn berry environments. This same function is used here -

const rootVersionKey = versionKeys.find((v) =>
isRootVersion(packageName, versions[v].version)
);

which causes problems in yarn berry environments.

@anogr
Copy link

anogr commented Jan 11, 2023

I still have the same problem in 15.4.5. We're using pnpm, not yarn.

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

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 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.