GeneratePackgageJson missing package
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
- 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
- [X] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
No response
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.
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"]
}
}
}
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 ?
@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
ok, i will try that. But anyway in the ealier version it worked without this workaround.
edit: The workaround from @stephenwade below is better, there are some issues with my workaround that I discovered after making this comment.
@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": "*"
}
}
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://[email protected]/charsleysa/postgres.git#335137370d4068041a09e25f4ca8d1a9d704a235"
}
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.
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.
- manually write package.json with specific dependencies
- use display import
import “xxxx”at the code entry.