@nrwl/node:build package.json not including all external dependencies.
See original GitHub issueCurrent Behavior
Code contains two dependencies
- express
- morgan
On serve or build. The generated package.json does not include morgan as a dependency, only express is included in package.json
project.targets.build.options.generatePackageJson = true
{
"name": "sample-api",
"version": "0.0.1",
"dependencies": {
"express": "^4.17.1"
},
"main": "main.js"
}
Expected Behavior
I expected the output of package.json to include morgan as a dependency.
{
"name": "sample-api",
"version": "0.0.1",
"dependencies": {
"express": "^4.17.1",
"morgan": "version"
},
"main": "main.js"
}
Steps to Reproduce
- create nx workspace.
- create new application using @nrwl/node.
- create a express server with morgan middleware
import * as express from 'express'
import * as morgan from 'morgan'
const app = express()
app.use(morgan('common'))
app.get('/', (req ,res) => {
return res.status(200).json({ message:'sample api'})
})
const port = 3000 || process.env.APP_PORT
app.listen(port, () => {
console.log(`App listening on http://localhost:${port}`)
})
- In workspace.json set
project.targets.build.options.generatePackageJson = true. - Change build location to apps/app_name/build .
- Run nx r sample-api:serve or nx r sample-api:build .
- check apps/app_name/build/package.json . package.json does not include morgan as dependency.
Project entry in workspace.json
"sample-api": {
"root": "apps/sample-api",
"sourceRoot": "apps/sample-api/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:build",
"outputs": ["{options.outputPath}"],
"options": {
"progress": true,
"generatePackageJson": true,
"outputPath": "apps/sample-api/dist",
"main": "apps/sample-api/src/main.ts",
"tsConfig": "apps/sample-api/tsconfig.app.json",
"assets": ["apps/sample-api/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/sample-api/src/environments/environment.ts",
"with": "apps/sample-api/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"executor": "@nrwl/node:execute",
"options": {
"buildTarget": "sample-api:build"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["apps/sample-api/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/sample-api"],
"options": {
"jestConfig": "apps/sample-api/jest.config.js",
"passWithNoTests": true
}
}
}
},
This issue may not be prioritized if details are not provided to help us reproduce the issue.
Failure Logs
N/A
Environment
node 14 ubuntu LTS 20
Issue Analytics
- State:
- Created 2 years ago
- Reactions:18
- Comments:14 (1 by maintainers)
Top Results From Across the Web
nx: How to keep external dependencies per app?
json to compiled results under dist folder (for applications built with @nrwl/node:webpack , need to add "generatePackageJson": true - ref).
Read more >Project Configuration - Nx
Projects can be configured in package.json (if you use npm scripts and not Nx executors) and project.json (if you use task executors). Both...
Read more >nrwl-nx/community - Gitter
In your build proccess just copy over the other package.json with the runtime ... 1 is include everything (default) in the bundle, the...
Read more >Improved Next.js support, auto-populated publishable library ...
json in your workspace. To make this easier, Nx now populates your package.json with the dependencies your library depends on at build time!...
Read more >package.json - npm Docs
Therefore, the name can't contain any non-URL-safe characters. Some tips: Don't use the same name as a core Node module. Don't put "js"...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I am having the same issue - it seems like some dependencies, especially those from libs are not included in the generated package.json. This makes containerizing a single application really difficult.
I have the same issue with a lot more packages like nestjs config, gcp storage, luxon