nx: "NX Cannot find module '@nrwl/nx-linux-arm64-gnu'" when running angular universal in a node:18 docker

Current Behavior

I just migrated using nx migrate latest

angular packages: 15.1.1 => 15.2.1

@nrwl/angular: 15.7.2 => 15.8.5
@nrwl/webpack: 15.7.2 => 15.8.5

I’m running angular universal in development mode and start it in a docker node:18

Now I get the following error: > NX Cannot find module '@nrwl/nx-linux-arm64-gnu'

As described in a similar issue, https://github.com/nrwl/nx/issues/8969 I tried to delete my node_modules and clear my cache.

It seems like my application works if I run my nx command outside docker: nx run my-app:serve-ssr

When starting my docker image, it throws the error above.

If i check my package-lock.json the package is listed under “optionalDependencies”: "@nrwl/nx-linux-arm64-gnu": "15.8.5"

Expected Behavior

After the migration it may should have installed the missing module @nrwl/nx-linux-arm64-gnu and run.

GitHub Repo

No response

Steps to Reproduce

Docker Image:

FROM node:18

RUN mkdir -p /app
WORKDIR /app/

COPY package*.json ./
COPY decorate-angular-cli.js ./decorate-angular-cli.js
RUN npm install -g @angular/cli@15 @angular-devkit/build-angular@15

RUN nx run my-app:serve-ssr

Nx Report

Node : 18.14.2
   OS   : darwin arm64
   npm  : 9.5.0
   
   nx                      : 15.8.5
   @nrwl/js                : 15.8.5
   @nrwl/jest              : 15.8.5
   @nrwl/linter            : 15.8.5
   @nrwl/workspace         : 15.8.5
   @nrwl/angular           : 15.8.5
   @nrwl/cli               : 15.8.5
   @nrwl/cypress           : 15.8.5
   @nrwl/devkit            : 15.8.5
   @nrwl/eslint-plugin-nx  : 15.8.5
   @nrwl/storybook         : 15.8.5
   @nrwl/tao               : 15.8.5
   @nrwl/webpack           : 15.8.5
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @nguniversal/express-engine : 15.2.0
   apollo-angular              : 4.2.1
   ng2-charts                  : 4.1.1
   @nguniversal/builders       : 15.2.0
   @storybook/angular          : 6.5.15

Failure Logs

No response

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 13
  • Comments: 30 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I faced a similar issues to yours, My resolution was to do the following steps:

  • Add this block in your Jenkins build stage withEnv(['NX_NON_NATIVE_HASHER=true']).
  • Remove --ignore-optional from your yarn install if any.

We are having a similar issue with ‘@nrwl/nx-linux-x64-gnu’. We are installing our dependencies with npm ci without any flags in GitHub actions on ubuntu-latest and node 18. https://github.com/kordis-leitstelle/kordis/actions/runs/4436908773/jobs/7785926966

I’ve updated the docs site to include some information on how to trouble shoot this issue.

In summary, it’s usually because of npm not including optional dependencies when node_modules already exist while doing an Nx update.

https://nx.dev/recipes/ci/troubleshoot-nx-install-issues

I’ll need to add another point of running npm install without using --no-optional.

I faced a similar issue just now.

Problem: my package.lock was corrupted because I’d been doing some really stupid shenanigans locally. When I committed, I was getting failed CI runs (very basic CI action setup) here: https://github.com/andyjessop/pivot/pull/15

Solution: Removed node_modules and package-lock.json, ran npm install and committed the changes. CI then passed.

blowing away package lock files can be a little dangerous as we end up getting new and potentially broken versions

Oh, thats the reason then.

Npm/yarn will install the specific native binary for your OS and arch. So if you run npm install on your darwin based os, you will only get @nrwl/nx-darwin-arm, but because your docker container is based on linux, it needs @nrwl/nx-linux-arm64-gnu. The only way to get that installed on a system is to execute npm install.

We can’t specifically add those packages as deps because there’s a hard requirement on the os and architecture of the host, and npm will fail the install if it detects a different os/arch than what is specified.

So I suggest to not mount the host node_modules, and do a npm install in the container.