Open thdk opened 7 months ago
Maybe this will help: https://nx.dev/nx-api/esbuild/executors/esbuild#thirdparty
Try to set the thirdParty
option to true
and build again. It did the trick for me (after struggling for quite a while). As I understand it the option gives you more control about the bundling scope.
Maybe this will help: https://nx.dev/nx-api/esbuild/executors/esbuild#thirdparty
Try to set the
thirdParty
option totrue
and build again. It did the trick for me (after struggling for quite a while). As I understand it the option gives you more control about the bundling scope.
Your solution is amazing! After struggling with it for nearly 24 hours, I stumbled upon your trick and it worked like a charm. Thank you!
Current Behavior
When enabling the
bundle
option of the @nx/esbuild:esbuild executor, then the third party dependencies are not present in the bundle. Instead, they are automatically marked asexternal
and therefor not included.This is not expected since the generated Dockerfile says that external dependencies would be included when using the bundle option with esbuild.
Then a Dockerfile is generated:
Saying that the install step can be removed when using
--bundle
.Expected Behavior
All dependencies should be bundled together with the source code so the
install
step in the Dockerfile can be removed as suggested in the comments of that Dockerfile.GitHub Repo
https://github.com/thdk/nx-esbuild-bundle-docker-repro
Steps to Reproduce
Create new workspace and add a node application
Remove the
npm install
line fromapps/api/Dockerfile
Set
bundle
option to true in build target ofapps/api/project.json
Build container image
=>
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
Seems like the issue could be with the following code where esbuild options are being generated.
https://github.com/nrwl/nx/blob/1d2bfde11a76af602ea7f3bc311245ef3c65ec35/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts#L25-L49
external
option is being filled by the esbuild executor here: https://github.com/nrwl/nx/blob/1d2bfde11a76af602ea7f3bc311245ef3c65ec35/packages/esbuild/src/executors/esbuild/esbuild.impl.ts#L50-L72