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

buildLibsFromSource: false doesn't work with Vite executors #17922

Closed
3 of 4 tasks
ms-tng opened this issue Jul 3, 2023 · 4 comments · Fixed by #17844
Closed
3 of 4 tasks

buildLibsFromSource: false doesn't work with Vite executors #17922

ms-tng opened this issue Jul 3, 2023 · 4 comments · Fixed by #17844
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@ms-tng
Copy link
Contributor

ms-tng commented Jul 3, 2023

Current Behavior

Suppose an app my-app uses the @nx/vite:build and/or @nx/vite:dev-server executors and depends on a lib my-lib. Then when the buildLibsFromSource option of the executor is set to false, my-lib is still built from source within my-app.

I created a reproducible example, see below.

This seems to be caused by a combination of two faulty behaviors:

  1. When the executor generates a temporary tsconfig.generated.json file, it tries to figure out whether the lib is buildable. It does so by checking if it has a target with the same name as the target currently being executed for the app, see
    context.targetName,
    That means when the target currently being executed is called serve, it looks for a target called serve in the lib, which doesn't make sense. The @nx/webpack:dev-server executor uses a hard-coded 'build' here, which is probably not optimal either but should work in most cases.
  2. When one fixes point 1. by patching @nx/vite, the tsconfig.generated.json file is generated correctly. However, it is still not respected by the build. I haven't figured out why, but I suspect it's because Nx Vite apps use the vite-tsconfig-paths plugin, which needs to be made aware of the generated tsconfig file, but isn't.

Expected Behavior

my-lib is not built from source, but its build artifact is used instead.

GitHub Repo

https://github.com/ms-tng/nx-buildlibsfromsource-repro

Steps to Reproduce

  1. Create a Vite app and a lib, where the app depends on the lib
  2. Set "buildLibsFromSource": false for the build and serve targets of the app
  3. Build the lib and build or serve the app
  4. Open the app in a browser and observe that the lib is built from its sources

Nx Report

Node   : 16.14.2
OS     : win32-x64
npm    : 8.5.0

nx                 : 16.4.2
@nx/js             : 16.4.2
@nx/linter         : 16.4.2
@nx/workspace      : 16.4.2
@nx/cypress        : 16.4.2
@nx/devkit         : 16.4.2
@nx/eslint-plugin  : 16.4.2
@nx/react          : 16.4.2
@nrwl/tao          : 16.4.2
@nx/vite           : 16.4.2
@nx/web            : 16.4.2
typescript         : 5.1.6

Failure Logs

No response

Operating System

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

Additional Information

No response

@mandarini mandarini added the scope: bundlers Issues related to webpack, rollup label Jul 3, 2023
@mandarini
Copy link
Member

mandarini commented Jul 3, 2023

There's already a PR in process, and it will be merged soon.

@mandarini mandarini linked a pull request Jul 3, 2023 that will close this issue
4 tasks
@ms-tng
Copy link
Contributor Author

ms-tng commented Jul 3, 2023

Thanks! Looking forward to trying the fix. :)

@ms-tng
Copy link
Contributor Author

ms-tng commented Aug 3, 2023

Note that this still doesn't work in Nx 16.6.0, for two reasons:

@github-actions
Copy link

github-actions bot commented Sep 3, 2023

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 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants