nx
nx copied to clipboard
generatePackageJson includes dependencies from "replace" file
Current Behavior
@nrwl/node:app with generatePackageJson:true
and fileReplacements
where "replace" contains dependency and "with" doesn't contain during build still includes dependency from "replace" file in result package.json
Expected Behavior
Result package.json shouldn't contain dependency from "replace" file
Steps to Reproduce
- Generate node app -
nx g @nrwl/node:app report-app
- Enable
"generatePackageJson": true
- Create files 'lib.ts' and 'lib.prod.ts' and add it to the "fileReplacements` section of production configuration
"fileReplacements": [
{
"replace": "apps/report-app/src/environments/environment.ts",
"with": "apps/report-app/src/environments/environment.prod.ts"
},
{
"replace": "apps/report-app/src/app/lib.ts",
"with": "apps/report-app/src/app/lib.prod.ts"
}
]
- Add any external dependency to the
lib.ts
file, i.e. puppeteer
import * as puppeteer from 'puppeteer';
export async function getBrowserInstance() {
return puppeteer.launch({
args: ['--no-sandbox', '--disable-dev-shm-usage'],
});
}
- nx run report-app:build:production
- Generated package.json will contain
puppeteer
as dependency however in result js file we don't have it.
Environment
Node : 16.10.0
OS : darwin x64
npm : 7.24.0
nx : 13.8.4
@nrwl/angular : undefined
@nrwl/cli : 13.8.4
@nrwl/cypress : 13.8.4
@nrwl/detox : undefined
@nrwl/devkit : 13.8.4
@nrwl/eslint-plugin-nx : 13.8.4
@nrwl/express : undefined
@nrwl/jest : 13.8.4
@nrwl/js : 13.8.4
@nrwl/linter : 13.8.4
@nrwl/nest : 13.8.4
@nrwl/next : undefined
@nrwl/node : 13.8.4
@nrwl/nx-cloud : undefined
@nrwl/react : 13.8.4
@nrwl/react-native : undefined
@nrwl/schematics : undefined
@nrwl/storybook : 13.8.4
@nrwl/tao : 13.8.4
@nrwl/web : 13.8.4
@nrwl/workspace : 13.8.4
typescript : 4.3.5
rxjs : 7.4.0
Any updates on this?
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
any news?
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏
do you expect fix?
We've replaced package.json
generation for libraries with the @nx/dependency-checks
lint rule, which will both check and fix dependencies. See: https://nx.dev/packages/eslint-plugin/documents/dependency-checks
For applications, the lint rule requires 16.8.0 (currently in beta, 16.8.0-beta.4), and include the includeTransitiveDependencies
option, which will scan for deps of deps (i.e. deps of workspace libs used in app). You can also use the ignoredFiles
option to exclude files in the workspace from being included in the deps check.
For other use cases, you will need to add a comment for Nx to ignore a dependency.
// nx-ignore-next-line
import * as xyz from 'xyz';
Closing this issue has we have better tools to deal with package.json
now for both libs and apps. In other cases just use the ignore comment.
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.