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.

Multi-library which depends on each other build error: Cannot find module

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

I create a repo which has two libraries, one of them depends on the other. When I build that library I get this error: Cannot find module xx.

How To Reproduce

You can reproduce it with the repo here. It will be ok if you build lib-a by run ng build lib-a, but get error if you build lib-b which import lib-a in lib-b/src/lib/lib-b.module.ts. I have set the path-mapping in lib-b/tsconfig.lib.json like below.

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "outDir": "../../out-tsc/lib",
    "target": "es2015",
    "declaration": true,
    "inlineSources": true,
    "types": [],
    "lib": ["dom", "es2018"],
    "baseUrl": "./",
    "paths": {
      "lib-a": ["../lib-a"]
    }
  },
  "angularCompilerOptions": {
    "annotateForClosureCompiler": true,
    "skipTemplateCodegen": true,
    "strictMetadataEmit": true,
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true,
    "enableResourceInlining": true
  },
  "exclude": ["src/test.ts", "**/*.spec.ts"]
}

Here is the error message when I run ng build lib-b

ERROR: projects/lib-b/src/lib/lib-b.module.ts(3,28): error TS2307: Cannot find module 'lib-a'.
projects/lib-b/src/lib/lib-b.module.ts(7,13): Error during template compile of 'LibBModule'
  Could not resolve lib-a relative to [object Object]..
projects/lib-b/src/lib/lib-b.module.ts(7,13): Error during template compile of 'LibBModule'
  Could not resolve lib-a relative to [object Object]..

An unhandled exception occurred: projects/lib-b/src/lib/lib-b.module.ts(3,28): error TS2307: Cannot find module 'lib-a'.
projects/lib-b/src/lib/lib-b.module.ts(7,13): Error during template compile of 'LibBModule'
  Could not resolve lib-a relative to [object Object]..
projects/lib-b/src/lib/lib-b.module.ts(7,13): Error during template compile of 'LibBModule'
  Could not resolve lib-a relative to [object Object]..

Expected Behaviour

Build multi-library which depends on each other successfully.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 5.1.0
@angular/*: 8.1.1
typescript: 3.4.3
rxjs: 6.4.0
node: 10.15.3
npm: 6.4.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, Aug 26, 2019

PS: you also need to add "lib-a/*": ["../../dist/lib-a/*"] to your paths

0reactions
github-actions[bot]commented, Jun 19, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem. This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem in a multiple library repo: can't inter-depend on each ...
If I create a repo made of two libraries for which one depends on the other ... -ng-date-utils/ts/src/module.ts:4:23: Cannot find module '.
Read more >
How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >
Xcode Previews doesn't work when u… - Apple Developer
I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the...
Read more >
Libtool - GNU.org
When building packages with static libraries, the libraries may depend circularly on each other (shared libs can too, but for those it doesn't...
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
In my case, I need to install the react-icons package so the freeCodeCamp icon can be resolved. I'll do that by running yarn...
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