nx
nx copied to clipboard
@nx/esbuild:esbuild does not include assets in watch or build
Current Behavior
Started a brand new node project from scratch with express. When I build the application, the assets directory is not copied into the dist folder. And when serving the application, all the assets return 404 since the assets directory is ignored.
:star: EDIT
I think the string version of the configuration may be broken, I looked at the docs for the "configuration playground" and trie the object format and the assets were handled correctly.
"assets": [
-"apps/nx-test/src/assets", // THIS DOES NOT WORK WITH ESBUILD
+ { // THIS DOES WORK
+ "glob": "**/*",
+ "input": "apps/nx-test/src/assets",
+ "output": "apps/nx-test/src/assets",
+ "ignore": [".gitkeep"]
+ }
],
Expected Behavior
assets are copied over just like they are in all other scenarios.
GitHub Repo
https://github.com/paustint/nx-bug-report-1
Steps to Reproduce
In provided repo:
run npm run build
and notice assets are not copied over.
run npm run start
and notice curl http://localhost:3000/assets/test.json
does not return file that should be returned.
If you want to try from scratch like I did to create above repo:
npx create-nx-workspace@latest
> NX Let's create a new workspace [https://nx.dev/getting-started/intro]
✔ Where would you like to create your workspace? · nx-test
✔ Which stack do you want to use? · node
✔ What framework should be used? · express
✔ Integrated monorepo, or standalone project? · integrated
✔ Application name · nx-test
✔ Would you like to generate a Dockerfile? [https://docs.docker.com/] · Yes
✔ Set up CI with caching, distribution and test deflaking · github
> NX Creating your v18.0.2 workspace.
✔ Installing dependencies with npm
✔ Successfully created the workspace: nx-test.
✔ CI workflow with Nx Cloud has been generated successfully
✔ CI workflow has been generated successfully
Nx Report
npx nx report
> NX Report complete - copy this into the issue template
Node : 18.16.0
OS : darwin-arm64
npm : 7.6.3
nx : 18.0.2
@nx/js : 18.0.2
@nx/jest : 18.0.2
@nx/linter : 18.0.2
@nx/eslint : 18.0.2
@nx/workspace : 18.0.2
@nx/devkit : 18.0.2
@nx/esbuild : 18.0.2
@nx/eslint-plugin : 18.0.2
@nx/node : 18.0.2
@nrwl/tao : 18.0.2
typescript : 5.3.3
Failure Logs
N/A
Package Manager Version
No response
Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
I first encountered this on my existing project, and created a new project from scratch to see what I might be doing wrong.... but the default configuration out of the box is broken.
Thanks for the workaround here, I am also seeing this issue but switching to the glob object fixed it for now 👍🏻
I'm also experiencing this issue with latest nx (19.3.1), also glob pattern isn't working for md
files
any updates on this?
You can change the string from "apps/nx-test/src/assets"
to "apps/nx-test/src/assets/**/*"
. This fixed it for me without using the object syntax:
In project.json
, targets.build.options
:
"assets": ["apps/server/src/assets/**/*"],
The assets are copied to the dist/apps/{app-name]/src/assets
directory.