question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@nrwl/node:build package.json not including all external dependencies.

See original GitHub issue

Current 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

  1. create nx workspace.
  2. create new application using @nrwl/node.
  3. 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}`)
})

  1. In workspace.json set project.targets.build.options.generatePackageJson = true .
  2. Change build location to apps/app_name/build .
  3. Run nx r sample-api:serve or nx r sample-api:build .
  4. 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:open
  • Created 2 years ago
  • Reactions:18
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
moterinkcommented, Mar 11, 2022

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.

6reactions
Mistic92commented, Oct 14, 2021

I have the same issue with a lot more packages like nestjs config, gcp storage, luxon

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found