nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.29k stars 2.32k forks source link

Next JS: Shared assets are not copied to the public folder on running 'nx build appName' #4411

Closed Miciurash closed 3 years ago

Miciurash commented 3 years ago

[x ] I am running the latest version [x ] I checked the documentation (nx.dev) and found no answer [x ] I checked to make sure that this issue has not already been filed [x ] I'm reporting the issue to the correct repository (not related to React, Angular or any dependency)

Current Behavior

When creating a shared assets library the assets are not copied to the public folder in Next.js

Expected Behavior

Assets mapping should work for Next.js similar to how it works for other app types. Not sure if this was ever implemented because Next.js has a different folder structure.

Steps to Reproduce

Run the project in this repo: https://github.com/Miciurash/nx-nextjs-shared-assets-bug/tree/main/bug-nextjs-shared-assets

There is a cat.jpg image that is supposed to be shared from libs to the nextjs app.

I think it might be related to #3019 (https://github.com/nrwl/nx/issues/3019)

Failure Logs

Failed to load resource: the server responded with a status of 404 (Not Found) for http://localhost:4200/assets/cat.jpg

Environment

Node : 15.3.0 OS : darwin x64 npm : 6.14.10

nx : Not Found @nrwl/angular : Not Found @nrwl/cli : 11.0.20 @nrwl/cypress : 11.0.20 @nrwl/devkit : 11.0.20 @nrwl/eslint-plugin-nx : 11.0.20 @nrwl/express : Not Found @nrwl/jest : 11.0.20 @nrwl/linter : 11.0.20 @nrwl/nest : Not Found @nrwl/next : 11.0.20 @nrwl/node : Not Found @nrwl/react : 11.0.20 @nrwl/schematics : Not Found @nrwl/tao : 11.0.20 @nrwl/web : 11.0.20 @nrwl/workspace : 11.0.20 typescript : 4.0.5

dbrody commented 3 years ago

Any update on this? I'm trying to get the same thing to work.

bekos commented 3 years ago

@Miciurash @dbrody This is fixed via 1f534317d03251deaf231e2f5f3de0905b4627e7 and is part of latest release, ie v11.2.0 One thing I noticed though in your configuration, is that assets should be an array, inside the options.

"options": {
   .....
    "assets": [
      {
        "input": "libs/shared/assets/src/lib",
        "glob": "**/*",
        "output": "assets"
      }
    ],
  .....
D1no commented 2 years ago

Thank you @bekos — this helped me to figure out how to get an assets folder, sitting in the root of the repository, outside of the nx workspaces subfolder properly referenced.

I'm new to nx and googled quite a bit: Is there a schema definition file or deeper documentation of all the properties the project.json can take? In this one here i.e. doesn't mention assets.

dm-camelonta commented 2 years ago

Thank you @bekos — this helped me to figure out how to get an assets folder, sitting in the root of the repository, outside of the nx workspaces subfolder properly referenced.

I'm new to nx and googled quite a bit: Is there a schema definition file or deeper documentation of all the properties the project.json can take? In this one here i.e. doesn't mention assets.

I was wondering the same questions. Didn't really understand how people wrote stuff without any documentation on it. But if I'm not mistaken NX started as some kind of extension(?) to Angular CLI. So I had a look there and it did help me. Not sure if it's exactly corresponding to nx, but looks lika a lot of things are the same.

https://angular.io/guide/workspace-config

Miciurash commented 2 years ago

Thank you @bekos! Not sure how this got lost in my threads!

carlosrsabreu commented 1 year ago

We are having the same issue.

We have followed this guide: https://nx.dev/recipes/other/deploy-nextjs-to-vercel but the public folder is not being considered.

Steps:

Result: no robots.txt for our website in vercel

Nx 14.8.6 Next 12.3.1


UPDATE: We have found a solution...

By adding --outputPath=. to the Vercel build command:

image

github-actions[bot] commented 1 year ago

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.