Cannot serve @nrwl/node project referencing a buildable library
See original GitHub issueCurrent 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:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top 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 >
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
Solution
I managed to fix the issue by adding
"buildLibsFromSource": true
to thebuild
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 ownbuild
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 intmp/apps/app-name
folder that expects libraries to be built into their destination location (dist/lib/lib-name
by default). Thistsconfig
is then used by the application to locate the dependencies.tsconfig
is generated here: https://github.com/nrwl/nx/blob/2824794a92913624e59d00201ef5dfa936f842fe/packages/workspace/src/utils/buildable-libs-utils.ts#L133buildLibsFromSource
option is handled here: https://github.com/nrwl/nx/blob/2824794a92/packages/node/src/builders/build/build.impl.ts#L40Sorry 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.