nx icon indicating copy to clipboard operation
nx copied to clipboard

@nrwl/next static assets 404 with @nrwl/next:server executor

Open pmualaba opened this issue 2 years ago • 0 comments

Current Behavior

When using the @nrwl/next:server executor (nx serve), static assets are served only from apps/app/public source folder. Even when we configure project.json like this:

"options": { "root": "apps/app", "outputPath": "dist/apps/app", "assets": [ { "input": "libs/ui/static", "glob": "**/*", "output": "" }, { "input": "libs/ui/icons/assets", "glob": "**/*", "output": "assets/icons" } ] },

This results in 404 resource not found for all static assets that are moved out of the next public folder into the nx library when launching the local dev server with nx serve app

Expected Behavior

nx serve app SHOULD serve static assets according to the configuration in project.json and NOT serve the static assets only from next public folder

Steps to Reproduce

This issue may not be prioritized if details are not provided to help us reproduce the issue.

Failure Logs

image

Environment

"next": "12.2.3",

NX Report complete - copy this into the issue template

Node : 16.15.0 OS : linux x64 yarn : 3.2.2

nx : 14.5.4 @nrwl/angular : Not Found @nrwl/cypress : 14.5.4 @nrwl/detox : Not Found @nrwl/devkit : 14.5.4 @nrwl/eslint-plugin-nx : 14.5.4 @nrwl/express : Not Found @nrwl/jest : 14.5.4 @nrwl/js : 14.5.4 @nrwl/linter : 14.5.4 @nrwl/nest : 14.5.4 @nrwl/next : 14.5.4 @nrwl/node : 14.5.4 @nrwl/nx-cloud : 14.3.0 @nrwl/nx-plugin : Not Found @nrwl/react : 14.5.4 @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.5.4 @nrwl/web : 14.5.4 @nrwl/workspace : 14.5.4 typescript : 4.7.4

Community plugins: @nx-go/nx-go: 2.6.0 @nx-tools/nx-docker: 3.0.2 nest-commander-schematics: 3.0.0

pmualaba avatar Aug 09 '22 20:08 pmualaba

This commit is the one that is responsible for breaking local dev resulting in 404 on static assets when you execute nx run app:serve:development in a local dev environment:

https://github.com/nrwl/nx/commit/8075cb9a9fc43f12eb0a1a58853167a27b3452d9

pmualaba avatar Aug 18 '22 12:08 pmualaba

This should be working in latest version. See demo here https://github.com/jaysoo/nx-demo-issue-11524

Note that since the dev server uses public/ folder in source, it will need to be gitignored. We'll look at potential solutions for not needing this gitignore (if we can provide multiple "public" paths to the dev server somehow.

For now you can just gitignore the assets. :)

jaysoo avatar Sep 01 '22 18:09 jaysoo

Sorry for the ping but this is still and issue if you already use the public folder for "non shared" assets on a particular next app.

For example, until now we have a UI library with assets shared with many next application in the mono repo an every next app have their own assets on the public folder, when serve everything is move to a temporal folder and serve from there.

Now everything is move to the next apps public folder, to everyone of them, and we cannot ignore the public folder, because as said there are assets only for that next app there.

Of course we can create an external assets folder and copy, but I think it's works much better before, when you can add a temporal outputPath where all are moved and served for development.

Thanks

Puertas avatar Sep 13 '22 14:09 Puertas