Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeneratePackgageJson missing package #26604

Open
1 of 4 tasks
DanielStoehr opened this issue Jun 20, 2024 · 9 comments
Open
1 of 4 tasks

GeneratePackgageJson missing package #26604

DanielStoehr opened this issue Jun 20, 2024 · 9 comments
Assignees
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug

Comments

@DanielStoehr
Copy link

DanielStoehr commented Jun 20, 2024

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

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@ndcunningham
Copy link
Contributor

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
Copy link
Author

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
Copy link

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
Copy link

phihochzwei commented Jun 27, 2024

@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
Copy link
Author

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

@joe-passenger
Copy link

@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

I've been doing the same thing, but in the new package.json file, you can just specify the version as "*" so that the version will still be controlled by the main package.json file.

{
  "name": "my-app-name",
  "dependencies": {
    "mssql": "*"
  }
}

@AgentEnder AgentEnder added the scope: node Issues related to Node, Express, NestJS support for Nx label Jul 8, 2024
@charsleysa
Copy link

I'm having the same issue with the following dependency:

        "postgres": "charsleysa/postgres#fix-errors-compiled",

I can work around it by adding the following to the package.json in the app root:

    "dependencies": {
        "postgres": "git+ssh://git@github.com/charsleysa/postgres.git#335137370d4068041a09e25f4ca8d1a9d704a235"
    }

@stephenwade
Copy link
Contributor

I have the same issue with typeorm and mysql2 because our code doesn't depend on mysql2 directly. TypeORM tries to load it when you pass type: 'mysql' in the connection options.

I fixed it by adding import 'mysql2'; at the top of my TypeORM config file so that Nx knows that it is a dependency of that file. You might need to add import 'mssql'; somewhere in your project.

@StringKe
Copy link

StringKe commented Dec 17, 2024

Is there not currently some way to manually configure the dependencies that need to be included?

typeorm uses dynamic loading of dependencies, I checked nx about dynamic loading of dependencies and currently generatePackageJson doesn't handle it correctly.

About use * dependencies

{
  "name": "aic-api",
  "dependencies": {
    "pg": "*"
  }
}

Currently the use of wildcards is not replaced with a specific version after compilation

{
  "name": "aic-api",
  "dependencies": {
    "@bull-board/api": "6.5.3",
    "@bull-board/express": "6.5.3",
    "@bull-board/nestjs": "6.5.3",
    "@liaoliaots/nestjs-redis": "10.0.0",
    "@nestjs/bullmq": "10.2.3",
    "@nestjs/common": "10.4.15",
    "@nestjs/core": "10.4.15",
    "@nestjs/platform-express": "10.4.15",
    "@nestjs/schedule": "4.1.2",
    "@nestjs/typeorm": "10.0.2",
    "@supercharge/request-ip": "1.2.0",
    "axios": "1.7.8",
    "body-parser": "1.20.3",
    "bullmq": "5.34.0",
    "cookie-parser": "1.4.7",
    "decimal.js": "10.4.3",
    "dotenv-expand": "12.0.1",
    "express": "4.21.2",
    "glob": "11.0.0",
    "hash-wasm": "4.12.0",
    "ioredis": "5.4.1",
    "lodash": "4.17.21",
    "luxon": "3.5.0",
    "nanoid": "3.3.7",
    "nest-commander": "3.15.0",
    "nestjs-cls": "4.5.0",
    "openai": "4.76.1",
    "pg": "*",
    "proper-lockfile": "4.1.2",
    "reflect-metadata": "0.1.14",
    "rxjs": "7.8.1",
    "typeorm": "0.3.20",
    "uuid": "11.0.3",
    "valibot": "1.0.0-beta.7"
  },
  "main": "main.js"
}


Temporary solution: generatePackageJson.

  1. manually write package.json with specific dependencies
  2. use display import import “xxxx” at the code entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests

8 participants