Description
Documentation issue
- Reporting a typo
- Reporting a documentation bug
- Documentation improvement
- Documentation feedback
Is there a specific documentation page you are reporting?
https://nx.dev/technologies/react/next/introduction#building-projects
Additional context or description
In @nx/next documentation it's stated that when you build your app, you get your output in the {workspaceRoot}/dist/{projectRoot} path.
This is not true.
If you create an Nx workspace with the command stated in the documentation:
npx create-nx-workspace@latest --preset=next
And then go ahead and build the app, generated artifacts go into .next folder inside the app's directory and not the {workspaceRoot}/dist/{projectRoot}
It also mentions that you can configure your vite.config.ts or project.json to customize the outputPath.
These two files are not coming out of the box so it's confusing to mention them.
If you were to add a project.json from Using the @nx/next:build executor as below:
{
"root": "apps/my-next-app",
"sourceRoot": "apps/my-next-app/src",
"targets": {
"build": {
"executor": "@nx/next:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/my-next-app"
}
}
}
}
There are two issues:
- You may not have src path in your Next.js app,
- You get typescript errors as below if you manage to build it.
Type error: File 'C:/Users/####/workspace-name/dist/app-name/.next/types/app/api/hello/route.ts' is not under 'rootDir' 'C:/Users/####/workspace-name/apps/app-name/src'. 'rootDir' is expected to contain all source files.
The file is in the program because:
Root file specified for compilation
Next.js build worker exited with code: 1 and signal: nul