Skel
Skel

Reputation: 1667

NRWL NX importing lib error TS2307: Cannot find module '@eduboard/interfaces'

I've just created a new NX project for work and I've created a lib for out interfaces to have them on the backend and the front end.

I'm getting this error when I compile

apps/askeddi/src/app/pages/global-admin/global-admin.component.ts(5,38): error TS2307: Cannot find module '@eduboard/interfaces'.

From everything i have read is that i have done nothing wrong but its asking for a module and its just an index.ts file.

export * from './lib/user';
export * from './lib/global-admin-dashboard';

And this the global-admin-dashboard

interface Schools {
  total: number;
  active: number;
  usingAssessor: number;
}

interface TotalNActive {
  total: number;
  active: number;
}

export interface GlobalAdminDashboard {
  schools: Schools;
  schoolGroups: TotalNActive;
  users: TotalNActive;
}

Upvotes: 19

Views: 28058

Answers (7)

RomainG
RomainG

Reputation: 597

I have faced a similar issue, I have forget to write ".ts" extension of a file and VSCode has auto interprete the file as a TS file.

So, in my case, just fix the extension file by adding ".ts" solve my issue.

Upvotes: 0

super7egazi
super7egazi

Reputation: 773

DON'T play with NX configuration. Just delete dist and node_modules and install again. I think it is a bug that they need to fix

Upvotes: 1

MrJH
MrJH

Reputation: 11

I fixed it with the idea of chabu, but I only do an npm i without deleting the node_modules folder.

Upvotes: 0

Ari Seyhun
Ari Seyhun

Reputation: 12531

You need to specify the location of your library for TypeScript to locate.

Add your library to the tsconfig.json at the root of your project under "paths":

{
  "compilerOptions": {
    ...
    "paths": {
      "@package/my-lib": ["libs/my-lib/src/index.ts"]
    }
  }
}

You may need to reload VSCode to have TypeScript reload the tsconfig.json.

Upvotes: 15

Paul Ryan
Paul Ryan

Reputation: 1509

For those that upgraded from nx 6/7 to 8 or 9 you may need to verify your angular.json for libraries is is using "builder": "@nrwl/angular:package", instead of "builder": "@angular-devkit/build-ng-packagr:build",. Without this change the system will attempt to use the angular-cli builder which has no knowledge of the rest of the workspace.

Upvotes: 0

chabu
chabu

Reputation: 121

nx team should pay some attention to this issue. I had same issue when I was trying out the tutorial on the nx.dev website. I read on some other thread that if you delete the node_modules folder and re-run npm install, the issue disappears. I tried it and it worked. Really disappointing.

As mentioned in the other answer, I don't think you need to specify paths in every project where you use the library. That breaks some basic architectures/benefits provided by nx.

Upvotes: 5

Skel
Skel

Reputation: 1667

I found out how to fix my problem.

So inside the tsconfig.app.json file, I added this to the paths.

"@eduboard/interfaces" : [
  "../../../libs/interfaces/src/index"
  ]

I had to go back a fair few because I had it have a baseURL set to src/

Upvotes: 18

Related Questions