nx icon indicating copy to clipboard operation
nx copied to clipboard

generatePackageJson includes dependencies from "replace" file

Open psamusev opened this issue 2 years ago • 5 comments

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

  1. Generate node app - nx g @nrwl/node:app report-app
  2. Enable "generatePackageJson": true
  3. 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"
            }
          ]
  1. 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'],
  });
}
  1. nx run report-app:build:production
  2. 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

psamusev avatar Mar 04 '22 14:03 psamusev

Any updates on this?

EByrdS avatar Jul 05 '22 14:07 EByrdS

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! 🙏

github-actions[bot] avatar Jan 02 '23 00:01 github-actions[bot]

any news?

psamusev avatar Jan 04 '23 09:01 psamusev

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! 🙏

github-actions[bot] avatar Jul 04 '23 00:07 github-actions[bot]

do you expect fix?

psamusev avatar Jul 04 '23 07:07 psamusev

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.

jaysoo avatar Aug 31 '23 14:08 jaysoo

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.

github-actions[bot] avatar Oct 01 '23 00:10 github-actions[bot]