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.

Import library in library - error TS2307: Cannot find module

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

I have two libraries generated with Angular CLI. I also use Nrwl Nx

  1. <@scope>/hello-world-a
  2. <@scope>/hello-world-b

When I import hello-world-b in hello-world-a and try to build, I get the following error:

BUILD ERROR libs/hello-world-a/src/lib/hello-world-a.module.ts(3,35): error TS2307: Cannot find module ‘@<@scope>/hello-world-b’. libs\hello-world-a\src\lib\hello-world-a.module.ts(6,27): Error during template compile of ‘HelloWorldAModule’ Could not resolve @<@scope>/hello-world-b relative to D:/Projekte/Git/<@scope>-maps/libs/hello-world-a/src/lib/hello-world-a.module.ts… libs\hello-world-a\src\lib\hello-world-a.module.ts(6,27): Error during template compile of ‘HelloWorldAModule’ Could not resolve @<@scope>/hello-world-b relative to D:/Projekte/Git/<@scope>-maps/libs/hello-world-a/src/lib/hello-world-a.module.ts…

How To Reproduce

  1. ng generate library hello-world-a
  2. ng generate library hello-world-b

in hello-world-a.module.ts import HelloWorldBModule

This should look like this:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HelloWorldBModule } from '@<scope>/hello-world-b';

@NgModule({
  imports: [CommonModule, HelloWorldBModule]
})
export class HelloWorldAModule {}

Then run: ng-packagr -p libs/hello-world-a/package.json

Expected Behaviour

I expect to import one library in another library without error

Version Information

ng-packagr: 4.1.0
@angular/*: 6.1.0
typescript: 2.7.2
rxjs: 6..2.2.
node: 8.11.3
npm: 5.6.0
@nrwl/nx: 6.2.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, Aug 24, 2018

You need ng-packagr, but as a dependencies. As Angular CLI have a wrapper for it.

I think what you are describing is secondary entry points https://github.com/dherges/ng-packagr/blob/master/docs/secondary-entrypoints.md

Sorry for the short reply but I am currently commuting

On Fri, 24 Aug 2018 at 18:55, Daniel Groh notifications@github.com wrote:

Do you mean, if I use Angular CLI and Nrwl I don’t need ng-packagr at all? How do I publish my libraries to npm ? Doing like you said, I would have to publish all my libraries instead of single ones. I thought that is the reason for this sample: https://github.com/dherges/nx-packaged

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dherges/ng-packagr/issues/1058#issuecomment-415818414, or mute the thread https://github.com/notifications/unsubscribe-auth/AQv-WsT0e3c4u-pecEGZLTCCuPvt-odKks5uUDAGgaJpZM4WLiQl .

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

Angular 6/7 Consuming a custom library throws error TS2397
Now i'm ready to build my project with: ng serve cms This will throw the following error: projects/cms/src/app/app.module.ts(52,30): error ...
Read more >
Webstorm cannot find imports after rebuild
Elena Pogorelova The imports show up with the red squiggly underline; hovering on them shows the error: `TS2307: Cannot find module '@app/shared ...
Read more >
cannot find module or its corresponding type declarations
To solve the "Cannot find module `fs` or its corresponding type declarations" error, install the types for node by running the command `npm...
Read more >
Fix error: cannot find module 'x' in Node.js or 'express'
Also, you can fix the Cannot find module 'X' Error in TypeScript project by installing type definitions for all your packages the project...
Read more >
How to import my own module from a test file? - Reddit
"Cannot find module '..' or its corresponding type declarations.ts (2307)". If I ignore the error and run the test, it all works fine...
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