question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building project graph on postinstall causes process to incorrectly exit with code 1 when libraries with individual project.json files are not yet present

See original GitHub issue

Current Behavior

Building the project graph in the postinstall step breaks workspace dependency installation.

Expected Behavior

Even if an error occurs while building the project graph nx should not error and break the whole installation as stated here. It seems this started to happen in v13 after this PR.

Steps to Reproduce

  1. Create a fresh nx repo.
  2. Create a couple of libraries with independent project.json files.
  3. Delete the libs folder and the node modules folder
  4. Try to install the dependencies of the repo.

After this it will say that the daemon couldn’t finish the graph build, but in a docker container this will cause the whole installation to error out as per this condition

My suspicion is that despite that we are catching any errors in the init.ts, it will still stop the installation since we are exiting the process here.

The reason why the libraries are actually not there at the point of installation is that we are copying them in our Dockerfile after the installation step in order to take advantage of docker layer caching. (changing application code can still reuse the dependency-install layer of the workspace)

   Node : 16.14.0
   OS   : darwin x64
   yarn : 1.22.17

   nx : 13.9.2
   @nrwl/angular : 13.9.2
   @nrwl/cypress : 13.9.2
   @nrwl/detox : undefined
   @nrwl/devkit : 13.9.2
   @nrwl/eslint-plugin-nx : 13.9.2
   @nrwl/express : undefined
   @nrwl/jest : 13.9.2
   @nrwl/js : 13.9.2
   @nrwl/linter : 13.9.2
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : 13.9.2
   @nrwl/nx-cloud : 13.1.6
   @nrwl/nx-plugin : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.9.2
   @nrwl/web : undefined
   @nrwl/workspace : 13.9.2
   typescript : 4.6.2
   rxjs : 7.5.5
   ---------------------------------------
   Community plugins:
   	 @ionic/angular: 6.0.12
   	 @ngrx/component: 13.0.2
   	 @ngrx/component-store: 13.0.2
   	 @ngrx/data: 13.0.2
   	 @ngrx/effects: 13.0.2
   	 @ngrx/entity: 13.0.2
   	 @ngrx/router-store: 13.0.2
   	 @ngrx/store: 13.0.2
   	 @ngrx/store-devtools: 13.0.2
   	 ts-node-builder: 2.2.0
   	 @funxtion/schematics: 0.0.1
   	 @ionic/cordova-builders: 6.1.0
   	 @ngrx/schematics: 13.0.2
   	 @nxtend/ionic-angular: 13.0.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tommazzo89commented, Apr 20, 2022

Thank you for the hint @ianldgs, but unfortunately the problem seems to be a different one here. Nx tries to compute the project graph in a postinstall hook that gets executed as part of npm install (actually it’s npm ci in the Dockerfile). This graph computation tries to open all project.json files, which are not available at this stage of the Docker build, because we only copy nx.json, package.json, tsconfig.base.json, package-lock.json, and workspace.json to allow Docker to cache the result of npm ci.

Nevertheless, I did try Nx v13.10.3, which fixes the bug that you mentioned (#9801), but the result is still the same: npm ci exits with the following error message:

>  NX   ENOENT: no such file or directory, open '/usr/src/polaris/apps/eff-controller/project.json'
1reaction
tommazzo89commented, Mar 23, 2022

We are having the same problem when building our Dockerfiles (e.g., here). Thank you for creating this issue @markpeterfejes!

With Docker the issue seems to depend on whether BuildKit is enabled or now. To reproduce the problem with our Docker builds you can follow these steps:

git clone https://github.com/polaris-slo-cloud/polaris-demos.git
cd polaris-demos/efficiency-demo

# This fails
DOCKER_BUILDKIT=0 docker build -f ./apps/eff-controller/Dockerfile --build-arg POLARIS_APP_TYPE=slo --build-arg POLARIS_APP_NAME=eff-controller -t polarissloc/eff-controller:latest .

# This works
DOCKER_BUILDKIT=1 docker build -f ./apps/eff-controller/Dockerfile --build-arg POLARIS_APP_TYPE=slo --build-arg POLARIS_APP_NAME=eff-controller -t polarissloc/eff-controller:latest .

I agree with @markpeterfejes that exiting the process with an error code here in buildProjectGraphWithoutDaemon() seems to be the problem.

The reason why the Docker build works with DOCKER_BUILDKIT=1 seems to be that createProjectGraphAsync() doesn’t correctly detect the Docker build here when using BuildKit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve npm install error “npm ERR! code 1”
try with deleting package-lock.json file and node_module folder then run npm cache clean --force. And try npm i again to install packages. If...
Read more >
Getting Started with Monorepo with Nx Nrwl - Rupesh Tiwari
The potential solution to this problem is Monorepo. You can put all of your JavaScript projects regardless of framework (angular, vue.js, ...
Read more >
Yocto Project Reference Manual
Features: Describes mechanisms for creating distribution, machine, and image features during the build process using the OpenEmbedded build system. Variables ...
Read more >
Nixpkgs 22.11 manual - NixOS
Nix expressions describe how to build packages from source and are collected in the nixpkgs repository. Also included in the collection are Nix...
Read more >
Jenkins User Handbook
[1: Domain-Specific Language]. Typically, the definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found