nx: Random error happens on vercel

Current Behavior

Getting this same error so randomly in different apps Error: Command "npx nx build <app name> --prod" exited with SIGTERM on vercel, fine on local build though. And by clicking redeploy will fix it.

Expected Behavior

Builds should pass without clicking redeploy to make them pass

Environment

` Node : 14.17.5 OS : darwin x64 yarn : 1.22.11

nx : 14.0.5 @nrwl/angular : Not Found @nrwl/cypress : 14.0.5 @nrwl/detox : Not Found @nrwl/devkit : 14.0.5 @nrwl/eslint-plugin-nx : 14.0.5 @nrwl/express : Not Found @nrwl/jest : 14.0.5 @nrwl/js : 14.0.5 @nrwl/linter : 14.0.5 @nrwl/nest : Not Found @nrwl/next : 14.0.5 @nrwl/node : Not Found @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : 14.0.5 @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.0.5 @nrwl/web : 14.0.5 @nrwl/workspace : 14.0.5 typescript : 4.6.4 rxjs : 6.6.7

Community plugins:

✨ Done in 1.51s.`

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 12
  • Comments: 19 (2 by maintainers)

Most upvoted comments

Update from the Vercel team on possible ways to fix this issue:

  • Add an environmental variable (NX_CACHE_DIRECTORY = /tmp/nx-cache) in Vercel. (It seems like they prefer this method)
  • Add to your build commands the following argument: --skip-nx-cache (This will effectively skip the NX cache ⚠️)

Experiencing the same problem.

My error is constant the same:

stack: "Error: Cannot find module 'typescript'\n" +

But on manual redeploy it works.

I have the similar error on Vercel. If we disable the command for ignoring the build step (npx nx-ignore frontend), it starts working with a cache as usual. However, it crashes with the following log for builds with the saved cache.

[15:56:44.848] Cloning completed: 1.447s
[15:56:44.849] Running "npx nx-ignore frontend"
[15:56:54.034] ≫ Using Nx to determine if this project (frontend) is affected by the commit...
[15:56:56.808] ✅ - Build can proceed since frontend is affected
[15:56:58.526] Looking up build cache...
[15:57:17.324] Build cache downloaded [285.21 MB]: 18381.264ms
[15:57:17.649] Running "vercel build"
[15:57:18.325] Vercel CLI 28.1.2
[15:57:20.335] Installing dependencies...
[15:57:20.776] yarn install v1.22.17
[15:57:20.916] [1/4] Resolving packages...
[15:57:21.979] success Already up-to-date.
[15:57:21.982] $ patch-package
[15:57:22.169] patch-package 6.4.7
[15:57:22.170] Applying patches...
[15:57:22.176] @nrwl/next@14.5.2 ✔
[15:57:22.184] $ husky install
[15:57:22.258] husky - Git hooks installed
[15:57:22.264] Done in 1.50s.
[15:57:22.287] Detected Next.js version: 12.2.5
[15:57:22.555] Running "yarn nx build frontend --prod --skip-nx-cache"
[15:57:22.895] yarn run v1.22.17
[15:57:22.933] $ /vercel/path0/node_modules/.bin/nx build frontend --prod --skip-nx-cache
[15:57:23.311] nx run [project][:target][:configuration] [_..]
[15:57:23.311] 
[15:57:23.311] Run a target for a project
[15:57:23.311]     (e.g., nx run myapp:serve:production).
[15:57:23.312] 
[15:57:23.312]     You can also use the infix notation to run a target:
[15:57:23.312]     (e.g., nx serve myapp --configuration=production)
[15:57:23.312] 
[15:57:23.312]     You can skip the use of Nx cache by using the --skip-nx-cache option.
[15:57:23.312] 
[15:57:23.312] Options:
[15:57:23.313]       --version           Show version number  [boolean]
[15:57:23.313]       --prod              Use the production configuration  [boolean] [default: false]
[15:57:23.313]   -c, --configuration     Target configuration  [string]
[15:57:23.313]       --project           Target project  [string]
[15:57:23.313]       --output-style      Defines how Nx emits outputs tasks logs  [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes", "compact"]
[15:57:23.313]       --nx-bail           Stop command execution after the first failed task  [boolean] [default: false]
[15:57:23.313]       --nx-ignore-cycles  Ignore cycles in the task graph  [boolean] [default: false]
[15:57:23.314] 
[15:57:23.315] {
[15:57:23.315]   stack: "Error: Cannot find module 'typescript'\n" +
[15:57:23.315]     'Require stack:\n' +
[15:57:23.315]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js\n' +
[15:57:23.315]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/explicit-project-dependencies.js\n' +
[15:57:23.316]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/index.js\n' +
[15:57:23.316]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-project-graph.js\n' +
[15:57:23.316]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js\n' +
[15:57:23.316]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/server.js\n' +
[15:57:23.316]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/start.js\n' +
[15:57:23.317]     '    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)\n' +
[15:57:23.317]     '    at Function.Module._load (internal/modules/cjs/loader.js:746:27)\n' +
[15:57:23.317]     '    at Module.require (internal/modules/cjs/loader.js:974:19)\n' +
[15:57:23.317]     '    at require (internal/modules/cjs/helpers.js:101:18)\n' +
[15:57:23.317]     '    at new TypeScriptImportLocator (/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js:11:20)\n' +
[15:57:23.317]     '    at buildExplicitTypeScriptDependencies (/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/explicit-project-dependencies.js:7:27)\n' +
[15:57:23.318]     '    at buildExplicitTypescriptAndPackageJsonDependencies (/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/build-explicit-typescript-and-package-json-dependencies.js:10:98)\n' +
[15:57:23.319]     '    at buildExplicitDependenciesWithoutWorkers (/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-project-graph.js:161:117)\n' +
[15:57:23.319]     '    at buildExplicitDependencies (/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-project-graph.js:118:16)\n' +
[15:57:23.319]     '    at /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-project-graph.js:83:15',
[15:57:23.319]   message: "Cannot find module 'typescript'\n" +
[15:57:23.319]     'Require stack:\n' +
[15:57:23.320]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js\n' +
[15:57:23.320]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/explicit-project-dependencies.js\n' +
[15:57:23.320]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/index.js\n' +
[15:57:23.320]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-project-graph.js\n' +
[15:57:23.321]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js\n' +
[15:57:23.321]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/server.js\n' +
[15:57:23.321]     '- /vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/start.js\n' +
[15:57:23.321]     '\n' +
[15:57:23.321]     'Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.\n' +
[15:57:23.321]     'If the error persists, please run "nx reset".',
[15:57:23.321]   code: 'MODULE_NOT_FOUND',
[15:57:23.321]   requireStack: [
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/typescript-import-locator.js',
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/explicit-project-dependencies.js',
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-dependencies/index.js',
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/project-graph/build-project-graph.js',
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js',
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/server.js',
[15:57:23.322]     '/vercel/.npm/_npx/260/lib/node_modules/nx-ignore/node_modules/nx/src/daemon/server/start.js'
[15:57:23.323]   ]
[15:57:23.323] }
[15:57:23.340] error Command failed with exit code 1.
[15:57:23.340] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[15:57:23.349] Error! Command "yarn nx build frontend --prod --skip-nx-cache" exited with 1

Nx report:

   OS   : darwin x64
   yarn : 1.22.17

   nx : 14.5.2
   @nrwl/angular : Not Found
   @nrwl/cypress : 14.5.2
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.5.2
   @nrwl/eslint-plugin-nx : 14.5.2
   @nrwl/express : Not Found
   @nrwl/jest : 14.5.2
   @nrwl/js : 14.5.2
   @nrwl/linter : 14.5.2
   @nrwl/nest : Not Found
   @nrwl/next : 14.5.2
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : 14.5.2
   @nrwl/react : 14.5.2
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.5.2
   @nrwl/web : 14.5.2
   @nrwl/workspace : 14.5.2
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:

This still happens.

This issue has been automatically marked as stale because it hasn’t had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

Note: if you’re using @nrwl/nx-cloud and NX_CACHE_DIRECTORY together, make sure you’re using version @nrwl/nx-cloud@14.6.0 or greater.

It looks like there was a bug prior to 14.6.0 that did not respect NX_CACHE_DIRECTORY and always assumed node_modules/.cache/nx existed, which could not be the case when installing with NX_CACHE_DIRECTORY and would cause an error when building.

My next step will be to upgrade nx. We’re currently at v13.

Don’t get your hopes up, happens with nx 14.4.2 as well 😦