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.

Cannot serve @nrwl/node project referencing a buildable library

See original GitHub issue

Current Behavior

Similar to https://github.com/nrwl/nx/issues/3131, if you try to reference a library with a build target then it cannot be resolved by webpack.

Expected Behavior

It shouldn’t matter if a library is buildable/publishable or neither, it should be able to be referenced by applications.

Steps to Reproduce

Create a new workspace, then

yarn add @nrwl/node
nx generate @nrwl/node:application --name=test-app
nx generate @nrwl/node:library --name=test-lib --buildable --importPath=@test-org/test-lib

Then update apps/test-app/main.ts

import { testLib } from "@test-org/test-lib";

console.log('Hello World!');
console.log(someBuildableLib())

Failure Logs

yarn nx serve test-app

Results in error: Module not found: Error: Can't resolve '@test-org/test-lib'

If you remove test-lib.architect.build from workspace.json the problem goes away.

Environment

  nx : Not Found
  @nrwl/angular : Not Found
  @nrwl/cli : 10.3.1
  @nrwl/cypress : Not Found
  @nrwl/eslint-plugin-nx : 10.3.1
  @nrwl/express : Not Found
  @nrwl/jest : 10.3.1
  @nrwl/linter : 10.3.1
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : 10.3.1
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 10.3.1
  @nrwl/web : Not Found
  @nrwl/workspace : 10.3.1
  typescript : 4.0.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pf1guracommented, Nov 26, 2020

Solution

I managed to fix the issue by adding "buildLibsFromSource": true to the build target of the application.

This will basically cause the libraries to behave as they weren’t buildable/publishable in the context of that application. They will be bundled in the main.js file of generated application. And original libraries still have their own build target that can be used to build and publish the library if that is something we want.

Explanation

That is what I found about this flow. When this option is disabled, nx generates temporary tsconfig with path mappings in tmp/apps/app-name folder that expects libraries to be built into their destination location (dist/lib/lib-name by default). This tsconfig is then used by the application to locate the dependencies.

0reactions
bekoscommented, Mar 13, 2021

Sorry for late response 😞 Following the steps, using the latest version Nx, I am not able to reproduce the error. I will close this, as it seems that this is already fixed, but feel free to reopen if you still have issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nx/community - nrwl - Gitter
Hello all, I am using nrwl/node:package to build a ts node module, but it gives me error: ... for running against all the...
Read more >
How to make a buildable publishable library with Nx that is ...
If you want to publish a NPM package as a "universal package" to be consumed by Node.js and the browser, you would need...
Read more >
@nrwl/node | Nx
You can run your application with nx serve my-new-app , which starts it in ... nx g @nrwl/node:lib my-new-lib # If you want...
Read more >
Building AWS Serverless applications with NX Dev Tools on a ...
And a library. ng g @nrwl/workspace:lib common-util. Applying the Serverless framework to the workspace. To build AWS Serverless Application ...
Read more >
@nrwl/node - npm
Start using @nrwl/node in your project by running `npm i @nrwl/node`. ... Nx is a next generation build system with first class monorepo ......
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