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

esbuild version conflict in NX Angular project when running in production mode #27333

Closed
1 of 4 tasks
joh-klein opened this issue Aug 8, 2024 · 8 comments · Fixed by #27405
Closed
1 of 4 tasks

esbuild version conflict in NX Angular project when running in production mode #27333

joh-klein opened this issue Aug 8, 2024 · 8 comments · Fixed by #27405
Assignees
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug

Comments

@joh-klein
Copy link

Current Behavior

There seems to be a version conflict issue with esbuild while trying to run the project in a production environment. When I try to execute NODE_ENV=production npm ci in a Docker container, I get Error: Expected "0.23.0" but got "0.21.5", referring to esbuild.

Expected Behavior

The project should run successfully after executing NODE_ENV=production npm ci.

GitHub Repo

https://github.com/joh-klein/nx-examples

Steps to Reproduce

  1. Create a new NX workspace using npx create-nx-workspace@latest test1.
  2. Generate a new buildable Angular library using npx nx generate @nrwl/angular:lib --buildable.
  3. Try to install the prod dependencies using NODE_ENV=production npm ci.

Nx Report

NX   Report complete - copy this into the issue template

Node           : 20.16.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.8.1

nx                 : 19.5.7
@nx/js             : 19.5.7
@nx/jest           : 19.5.7
@nx/linter         : 19.5.7
@nx/eslint         : 19.5.7
@nx/workspace      : 19.5.7
@nx/angular        : 19.5.7
@nx/cypress        : 19.5.7
@nx/devkit         : 19.5.7
@nx/eslint-plugin  : 19.5.7
@nx/react          : 19.5.7
@nrwl/tao          : 19.5.7
@nx/web            : 19.5.7
@nx/webpack        : 19.5.7
typescript         : 5.5.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/cypress/plugin
@nx/jest/plugin
---------------------------------------
Community plugins:
@ngrx/component-store : 18.0.2
@ngrx/effects         : 18.0.2
@ngrx/entity          : 18.0.2
@ngrx/operators       : 18.0.2
@ngrx/router-store    : 18.0.2
@ngrx/store           : 18.0.2
@ngrx/store-devtools  : 18.0.2

Failure Logs

npm error code 1
npm error path /Users/[redacted]/nx-examples/node_modules/ng-packagr/node_modules/esbuild
npm error command failed
npm error command sh -c node install.js
npm error /Users/[redacted]/nx-examples/node_modules/ng-packagr/node_modules/esbuild/install.js:134
npm error     throw new Error(`Expected ${JSON.stringify(versionFromPackageJSON)} but got ${JSON.stringify(stdout)}`);
npm error           ^
npm error
npm error Error: Expected "0.23.0" but got "0.21.5"
npm error     at validateBinaryVersion (/Users/[redacted]/nx-examples/node_modules/ng-packagr/node_modules/esbuild/install.js:134:11)
npm error     at /Users/[redacted]/nx-examples/node_modules/ng-packagr/node_modules/esbuild/install.js:284:5
npm error
npm error Node.js v20.16.0
npm error A complete log of this run can be found in: /Users/[redacted]/.npm/_logs/2024-08-08T09_48_55_180Z-debug-0.log

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

A temporary workaround is to add this override to the package.json

  "overrides": {
    "ng-packagr": {
      "esbuild": "0.21.5"
    }
  }
@leosvelperez
Copy link
Member

Thanks for reporting this!

The issue comes from the ng-packagr package, which is maintained by the Angular team. You can raise an issue at https://github.com/ng-packagr/ng-packagr instead.

I'm closing this since it's not actionable by us.

@leosvelperez leosvelperez closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2024
@joh-klein
Copy link
Author

joh-klein commented Aug 8, 2024

Well, the problem only occurs in an nx wokspace! (I tried it with an angular only repository) Because @nx/angular is in dependencies and has the required peerDependency @angular-devkit/build-angular which itself has the optional peerDependency ng-packagr. And when I only want to install the prod dependencies the npm "magic" happens …

If I don't install ng-packagr as a devDependency but as a dependency NODE_ENV=production npm ci works as well.

@leosvelperez leosvelperez reopened this Aug 8, 2024
@leosvelperez leosvelperez added the scope: angular Issues related to Angular support in Nx label Aug 8, 2024
@leosvelperez leosvelperez self-assigned this Aug 8, 2024
@leosvelperez
Copy link
Member

Do you need @nx/angular as a production dependency? Are you using any of the runtime helpers from it? If not, you can move it to devDependencies.

@joh-klein
Copy link
Author

I never thought to move it to devDependecies since it is the nx default to put it into dependencies. I just tried that solution and it works!

Maybe it would be a good idea to put it into devDependencies by default? Or split @nx/angular into two packages for dev and prod dependencies?

@leosvelperez
Copy link
Member

I'm glad it worked.

I agree we should consider generating projects with it in devDependencies. The @nx/angular runtime helpers are a small subset of what the plugin offers and are not used by everyone. We'll look into doing so.

Moving the runtime helpers out of @nx/angular is something we've long discussed but we haven't yet decided to do so.

@joh-klein
Copy link
Author

Thank you for your help!

@joh-klein
Copy link
Author

Sorry, I should probably leave this open, right?

@joh-klein joh-klein reopened this Aug 9, 2024
FrozenPandaz pushed a commit that referenced this issue Aug 19, 2024
…endencies when using runtime helpers (#27405)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

New workspaces are generated with `@nx/angular` as a production
dependency even though the generated code does not use any runtime
helper from it.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

New workspaces should be generated with `@nx/angular` as a development
dependency. When generating a new MF host or dynamic MF application
(host or remote), the `@nx/angular` package should be moved to the
production dependencies because the generated code uses some runtime
helpers from it.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27333

(cherry picked from commit 1ae3c2d)
Copy link

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 Sep 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: angular Issues related to Angular support in Nx type: bug
Projects
None yet
2 participants