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.

Node "serve" target does not build dependencies that are buildable, or watch for changes

See original GitHub issue

Current Behavior

If you set up an NodeJS application which has a lib dependency in the workspace which is “buildable” then when you run nx serve your-app the lib will not be automatically built, and the serve will fail because its expecting to find the built output of the lib in the `dist/ directory.

If you nx build your-app it will build the dependency properly.

If you are “serving” the app after building the lib manually, it will not rebuild or restart the app if the lib is changed

Expected Behavior

I would expect that the lib is automatically built by running nx serve on the node app. I would also expect it to be watching for changes to the lib and automatically re-running the server.

Steps to Reproduce

The issue is reproduced in my public Nx repo here: https://github.com/devcyclehq/js-sdks

If you run nx serve example-nodejs-cloud-typescript then it will fail, because it can’t find the built output of the dependency in the dist/ directory.

Failure Logs

Environment

 NX   Report complete - copy this into the issue template

   Node : 16.13.2
   OS   : darwin x64
   yarn : 3.2.0

   nx : 14.0.5
   @nrwl/angular : Not Found
   @nrwl/cypress : 14.0.5
   @nrwl/detox : 14.0.5
   @nrwl/devkit : 14.0.5
   @nrwl/eslint-plugin-nx : 14.0.5
   @nrwl/express : Not Found
   @nrwl/jest : 14.0.5
   @nrwl/js : 14.0.5
   @nrwl/linter : 14.0.5
   @nrwl/nest : Not Found
   @nrwl/next : 14.0.5
   @nrwl/node : 14.0.5
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 14.0.5
   @nrwl/react-native : 14.0.5
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.0.5
   @nrwl/web : 14.0.5
   @nrwl/workspace : 14.0.5
   typescript : 4.6.3
   rxjs : 6.6.7

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
ajwoottocommented, Aug 16, 2022

I’m on Mac OS and experiencing the issue, so I don’t think that’s the culprit

0reactions
wolfie82commented, Nov 11, 2022

I ran into this and was able to solve it by updating my nx.json. Now if one of my apps depends on my library that has a generate target, it will automatically run on serve and build. I hope this helps someone.

"tasksRunnerOptions": {
  "default": {
    "runner": "nx/tasks-runners/default",
    "options": {
      "cacheableOperations": ["build", "lint", "test", "e2e", "generate"]
    }
  }
},
...
"targetDefaults": {
    "build": {
      "dependsOn": ["^generate", "^build"],
      "inputs": ["production", "^production"]
    },
    "serve": {
      "dependsOn": ["^generate"]
    },
    "test": {
      "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"]
    },
    "e2e": {
      "inputs": ["default", "^production"]
    },
    "lint": {
      "inputs": ["default", "{workspaceRoot}/.eslintrc.json"]
    }
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify local modules as npm package dependencies
json dependencies structure. Using the --save option in this command is simply putting "mymodule": "0.0.0" into my package.json ( ...
Read more >
Use cases for combined documentation of multiple targets in ...
Documentation for targets sub-hierarchies should continue to be buildable as separate units. If a target can be imported individually it can't ...
Read more >
Project Configuration - Nx
A common scenario is having to build dependencies of a project first before building the project. This is what the "dependsOn": ["^build"] property...
Read more >
Getting Started with Monorepo with Nx Nrwl - Rupesh Tiwari
Step : Let's take logger dependency on our applicationPermalink. Next lest run the build. npm run affected:build. Notice the app is building and ......
Read more >
Setup a Monorepo with PNPM workspaces and speed it up ...
Defining task dependencies (aka build pipeline) ... Note, we declare it as private because we don't want to publish it to NPM or...
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