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

"Error: Cannot find module './pnpm.cjs'" when building Nx monorepo with NIXPACKS_NX_APP_NAME set #1034

Open
1 task done
Nick-Lucas opened this issue Dec 23, 2023 · 2 comments
Labels
bug Something isn't working community

Comments

@Nick-Lucas
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When building an app within an Nx monorepo, with pnpm, pnpx build command fails with the below error

nixpacks build . --name myimagename -e NIXPACKS_NX_APP_NAME=api

╔═══════════════ Nixpacks v1.20.0 ══════════════╗
║ setup      │ nodejs_18, pnpm-8_x              ║
║───────────────────────────────────────────────║
║ install    │ pnpm i --frozen-lockfile         ║
║───────────────────────────────────────────────║
║ build      │ pnpx nx run api:build:production ║
║───────────────────────────────────────────────║
║ start      │ node dist/apps/api/main.js       ║
╚═══════════════════════════════════════════════╝

[+] Building 45.0s (12/14)                                                                                                            docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                  0.0s
 => => transferring dockerfile: 1.14kB                                                                                                                0.0s
 => [internal] load .dockerignore                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                       0.0s
 => [internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1702339400                                                                        0.8s
 => [stage-0  1/10] FROM ghcr.io/railwayapp/nixpacks:ubuntu-1702339400@sha256:1a9c1eed040aacf8f898be048210ef2d3366b1228373c4e6818362bb75611b32        0.0s
 => [internal] load build context                                                                                                                    11.1s
 => => transferring context: 1.02GB                                                                                                                  10.7s
 => CACHED [stage-0  2/10] WORKDIR /app/                                                                                                              0.0s
 => CACHED [stage-0  3/10] COPY .nixpacks/nixpkgs-bf744fe90419885eefced41b3e5ae442d732712d.nix .nixpacks/nixpkgs-bf744fe90419885eefced41b3e5ae442d73  0.0s
 => CACHED [stage-0  4/10] RUN nix-env -if .nixpacks/nixpkgs-bf744fe90419885eefced41b3e5ae442d732712d.nix && nix-collect-garbage -d                   0.0s
 => [stage-0  5/10] COPY . /app/.                                                                                                                    10.7s
 => [stage-0  6/10] RUN --mount=type=cache,id=PrhjbjBYoZA-/root/local/share/pnpm/store/v3,target=/root/.local/share/pnpm/store/v3 pnpm i --frozen-l  13.3s
 => [stage-0  7/10] COPY . /app/.                                                                                                                     8.7s 
 => ERROR [stage-0  8/10] RUN --mount=type=cache,id=PrhjbjBYoZA-node_modules/cache,target=/app/node_modules/.cache pnpx nx run api:build:production   0.1s 
------                                                                                                                                                     
 > [stage-0  8/10] RUN --mount=type=cache,id=PrhjbjBYoZA-node_modules/cache,target=/app/node_modules/.cache pnpx nx run api:build:production:              
0.127 node:internal/modules/cjs/loader:1080                                                                                                                
0.127   throw err;                                                                                                                                         
0.127   ^                                                                                                                                                  
0.127                                                                                                                                                      
0.127 Error: Cannot find module './pnpm.cjs'
0.127 Require stack:
0.127 - /nix/store/7nxrwg60is6i75nh3a6f4mk6yzs5203h-pnpm/bin/pnpx
0.127     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
0.127     at Module._load (node:internal/modules/cjs/loader:922:27)
0.127     at Module.require (node:internal/modules/cjs/loader:1143:19)
0.127     at require (node:internal/modules/cjs/helpers:119:18)
0.127     at Object.<anonymous> (/nix/store/7nxrwg60is6i75nh3a6f4mk6yzs5203h-pnpm/bin/pnpx:5:1)
0.127     at Module._compile (node:internal/modules/cjs/loader:1256:14)
0.127     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
0.127     at Module.load (node:internal/modules/cjs/loader:1119:32)
0.127     at Module._load (node:internal/modules/cjs/loader:960:12)
0.127     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12) {
0.127   code: 'MODULE_NOT_FOUND',
0.127   requireStack: [ '/nix/store/7nxrwg60is6i75nh3a6f4mk6yzs5203h-pnpm/bin/pnpx' ]
0.127 }
0.127 
0.127 Node.js v18.18.2
------
Dockerfile:24
--------------------
  22 |     # build phase
  23 |     COPY . /app/.
  24 | >>> RUN --mount=type=cache,id=PrhjbjBYoZA-node_modules/cache,target=/app/node_modules/.cache pnpx nx run api:build:production
  25 |     
  26 |     
--------------------
ERROR: failed to solve: process "/bin/bash -ol pipefail -c pnpx nx run api:build:production" did not complete successfully: exit code: 1
Error: Docker build failed

To reproduce

  1. Create Nx monorepo with an app in, using pnpm
  2. Build the app with nixpacks build . --name myimagename -e NIXPACKS_NX_APP_NAME=appname
  3. Build fails with pnpm.cjs error

Expected behavior

Build works

Environment

macOS locally, and Railway.app build env

@Nick-Lucas Nick-Lucas added the bug Something isn't working label Dec 23, 2023
Copy link
Contributor

Hello, @Nick-Lucas! Thanks for your submission.

Our team will respond soon. If you need more immediate help, try our Forum or our Discord. Thanks!

@Nick-Lucas
Copy link
Author

Workaround: override the build command with --build-cmd="pnpm nx run api:build:production --skip-nx-cache"

pnpx is broken in nixpacks, and also so is the nx cache if you don't include --skip-nx-cache too, the cache may fail the build due to some integrity issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community
Projects
None yet
Development

No branches or pull requests

1 participant