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

Viewed 11065

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;
}

5 Answers

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/

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.

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.

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.

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

Related