nrwl / nx

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

GeneratePackgageJson missing package #26604

Open DanielStoehr opened 1 week ago

DanielStoehr commented 1 week ago

Current Behavior

Hello, I´m using NX with NestJs and Angular. Now My NestJS App using typeorm with mssql. I want to create the packge json over my webpack config:

const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
const { join } = require('path');

module.exports = {
  output: {
    path: join(__dirname, '../../dist/apps/api'),
  },
  plugins: [
    new NxAppWebpackPlugin({
      target: 'node',
      compiler: 'tsc',
      main: './src/main.ts',
      tsConfig: './tsconfig.app.json',
      assets: ['./src/assets'],
      optimization: false,
      outputHashing: 'none',
      generatePackageJson: true,
    }),
  ],
};

here is my current package.json of my project:

{
  "name": "@material-requestment/source",
  "version": "1.0.0",
  "description": "TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nx run-many -t serve --all"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/animations": "~18.0.0",
    "@angular/cdk": "^18.0.3",
    "@angular/common": "~18.0.0",
    "@angular/compiler": "~18.0.0",
    "@angular/core": "~18.0.0",
    "@angular/forms": "~18.0.0",
    "@angular/material": "^18.0.3",
    "@angular/platform-browser": "~18.0.0",
    "@angular/platform-browser-dynamic": "~18.0.0",
    "@angular/router": "~18.0.0",
    "@nestjs/common": "^10.0.2",
    "@nestjs/core": "^10.0.2",
    "@nestjs/mapped-types": "*",
    "@nestjs/platform-express": "^10.0.2",
    "@nestjs/serve-static": "^4.0.2",
    "@nestjs/swagger": "^7.3.1",
    "@nestjs/typeorm": "^10.0.2",
    "angular-svg-icon": "^17.0.0",
    "mssql": "^10.0.2",
    "nx": "^19.3.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "typeorm": "^0.3.20",
    "zone.js": "~0.14.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~18.0.0",
    "@angular-devkit/core": "~18.0.0",
    "@angular-devkit/schematics": "~18.0.0",
    "@angular-eslint/eslint-plugin": "^18.0.1",
    "@angular-eslint/eslint-plugin-template": "^18.0.1",
    "@angular-eslint/template-parser": "^18.0.1",
    "@angular/cli": "~18.0.0",
    "@angular/compiler-cli": "~18.0.0",
    "@angular/language-service": "~18.0.0",
    "@nestjs/schematics": "^10.0.1",
    "@nestjs/testing": "^10.0.2",
    "@nx/angular": "19.3.0",
    "@nx/devkit": "19.3.0",
    "@nx/eslint": "19.3.0",
    "@nx/eslint-plugin": "19.3.0",
    "@nx/jest": "19.3.0",
    "@nx/js": "19.3.0",
    "@nx/nest": "19.3.0",
    "@nx/node": "19.3.0",
    "@nx/web": "19.3.0",
    "@nx/webpack": "19.3.0",
    "@schematics/angular": "~18.0.0",
    "@swc-node/register": "~1.9.1",
    "@swc/core": "~1.5.7",
    "@swc/helpers": "~0.5.11",
    "@types/jest": "^29.4.0",
    "@types/node": "18.16.9",
    "@typescript-eslint/eslint-plugin": "^7.3.0",
    "@typescript-eslint/parser": "^7.3.0",
    "@typescript-eslint/utils": "^8.0.0-alpha.28",
    "autoprefixer": "^10.4.0",
    "eslint": "~8.57.0",
    "eslint-config-prettier": "^9.0.0",
    "jest": "^29.4.1",
    "jest-environment-jsdom": "^29.4.1",
    "jest-environment-node": "^29.4.1",
    "jest-preset-angular": "~14.1.0",
    "nx": "19.1.1",
    "postcss": "^8.4.5",
    "prettier": "^3.3.2",
    "tailwindcss": "^3.0.2",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "typescript": "~5.4.2",
    "webpack-cli": "^5.1.4"
  },
  "nx": {}
}

after build my app the generated package.json is following:

{
  "name": "api",
  "version": "0.0.1",
  "dependencies": {
    "@nestjs/common": "10.3.9",
    "@nestjs/core": "10.3.9",
    "@nestjs/platform-express": "10.3.9",
    "@nestjs/serve-static": "4.0.2",
    "@nestjs/swagger": "7.3.1",
    "@nestjs/typeorm": "10.0.2",
    "reflect-metadata": "0.1.14",
    "rxjs": "7.8.1",
    "tslib": "2.6.3",
    "typeorm": "0.3.20"
  },
  "main": "main.js"
}

now can can not startup the app because the "mssql" package is missing

Expected Behavior

the mssql package should be included in the generated package json

GitHub Repo

No response

Steps to Reproduce

  1. nx build api

Nx Report

`NX   Report complete - copy this into the issue template

Node   : 20.12.2
OS     : linux-x64
npm    : 10.8.1

nx (global)        : 19.3.0
nx                 : 19.3.0
@nx/js             : 19.3.0
@nx/jest           : 19.3.0
@nx/linter         : 19.3.0
@nx/eslint         : 19.3.0
@nx/workspace      : 19.3.0
@nx/angular        : 19.3.0
@nx/devkit         : 19.3.0
@nx/eslint-plugin  : 19.3.0
@nx/nest           : 19.3.0
@nx/node           : 19.3.0
@nrwl/tao          : 19.3.0
@nx/web            : 19.3.0
@nx/webpack        : 19.3.0
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/webpack/plugin`

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

No response

ndcunningham commented 1 week ago

Hi, Can you show your project.json please?

If you are using inferred targets with Nest, at the moment we do not have support for it.

DanielStoehr commented 1 week ago

Here is my current project json:

{
  "name": "api",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/api/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "api:build"
      },
      "configurations": {
        "development": {
          "buildTarget": "api:build:development"
        },
        "production": {
          "buildTarget": "api:build:production"
        }
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/api/jest.config.ts"
      }
    },
    "build-migration-config": {
      "executor": "@nx/js:tsc",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist-mig",
        "main": "apps/api/src/typeorm.config.ts",
        "tsConfig": "apps/api/tsconfig.app.json",
        "rootDir": "."
      }
    },
    "makemigrations": {
      "executor": "nx:run-commands",
      "outputs": ["{options.outputPath}"],
      "options": {
        "cwd": "apps/api/src/migrations",
        "commands": ["sh ./makemigrations.sh"],
        "parallel": false
      },
      "dependsOn": ["build-migration-config"]
    },
    "migrate": {
      "executor": "nx:run-commands",
      "outputs": ["{options.outputPath}"],
      "options": {
        "cwd": "apps/api/src/migrations",
        "commands": [
          "npx typeorm -d /app/dist-mig/apps/api/src/app/typeorm.config.js migration:run"
        ]
      },
      "dependsOn": ["build-migration-config"]
    }
  }
}
phihochzwei commented 6 days ago

I am facing the same problem. We use https://github.com/simov/slugify in our project and all worked fine until the latest update. Is there any way to manually add packages to generated package.json ?

phihochzwei commented 6 days ago

@DanielStoehr I found a workaround in another issues comment, maybe this can help you as much as it did help me:

Just add a package.json in your Nest.js apps root which only contains the missing packages as dependencies. Worked for me

DanielStoehr commented 5 days ago

ok, i will try that. But anyway in the ealier version it worked without this workaround.