-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
outdatedscope: nextjsIssues related to NextJS support for NxIssues related to NextJS support for Nxtype: bug
Description
Current Behavior
NextJS project contains custom package.json file and this file is imported into next.config.js.
// next.config.js
const packageJsonAppVersion = require('./package.json').version;
console.log({ packageJsonAppVersion });When app is built, in the dist/ folder, the package.json file does not contain auto-generated information, like dependencies and scripts , but it is just a copy of project's package.json.
{
"name": "@custom-scope/nx-bug-next-package-json",
"version": "1.2.3"
}Expected Behavior
App's distribution code should contain correct auto-generated package.json file:
{
"name": "@custom-scope/nx-bug-next-package-json",
"version": "1.2.3",
"scripts": {
"start": "next start"
},
"dependencies": {
"react": "18.2.0",
"react-dom": "18.2.0",
"next": "14.0.4",
"typescript": "5.3.3"
}
}GitHub Repo
https://github.com/taurusx/nx-bug-next-package-json
Steps to Reproduce
- Download example repository or just start one from NX + NextJS app template:
pnpx create-nx-workspace@latest --preset=next - NextJS app needs to contain following changes (already set in example repo):
- Custom
package.jsonfile inside a project (NextJS app) directory; - Import of
package.jsoninnext.config.jsfile.
- Build an example app and check
dist/folder'spackage.jsonfile. (in example repo runpnpm nx build nx-bug-next-package-jsonto build an app)
Nx Report
Node : 20.9.0
OS : darwin-x64
pnpm : 8.3.1
nx : 17.3.1
@nx/js : 17.3.1
@nx/jest : 17.3.1
@nx/linter : 17.3.1
@nx/eslint : 17.3.1
@nx/workspace : 17.3.1
@nx/devkit : 17.3.1
@nx/eslint-plugin : 17.3.1
@nx/next : 17.3.1
@nx/react : 17.3.1
@nrwl/tao : 17.3.1
@nx/web : 17.3.1
typescript : 5.3.3Failure Logs
No response
Package Manager Version
pnpm 8.3.1
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
Bug location:
@nx/next:buildexecutor generatespackage.jsonwithupdatePackageJson(builtPackageJson, context);:
https://github.com/nrwl/nx/blob/master/packages/next/src/executors/build/build.impl.ts#L83 and next line- Copy step for
next.config.jsand its dependencies,createNextConfigFile(options, context);
https://github.com/nrwl/nx/blob/master/packages/next/src/executors/build/build.impl.ts#L105 - As long as there is
package.jsonimported insidenext.config.js, the function above (step 2.) sees it as a required dependency, so it copies it over, as well. Butpackage.jsonhas already been generated in step 1., so it gets overwritten.
Maybe package.json should be explicitly excluded from const moduleFilesToCopy = getRelativeFilesToCopy(...) https://github.com/nrwl/nx/blob/master/packages/next/src/executors/build/lib/create-next-config-file.ts#L74 ?
lasota-piotr
Metadata
Metadata
Assignees
Labels
outdatedscope: nextjsIssues related to NextJS support for NxIssues related to NextJS support for Nxtype: bug