bersling
bersling

Reputation: 19262

Typescript library 'has no exported member', even though I export it

My typescript compiler complains about 'has no exported member', even though I explicitly exported it and IntelliJ can even do the resolution.

So I try to:

import { libModuleLoader } from '@simpletests/testlib55';

which I export like this:

export const libModuleLoader = () => {
   ...
};

but I get the error: src/app/app.module.ts(4,10): error TS2305: Module '"/Users/Bersling/Desktop/IT-Projects/angular/tsng2/cons/src/app/node_modules/@simpletests/testlib55/index"' has no exported member 'libModuleLoader'.

When I click the "go to declaration" button in intellij it also finds the export:

enter image description here

I'm using Typsescript v2.3.4.

Upvotes: 3

Views: 2247

Answers (1)

bersling
bersling

Reputation: 19262

The problem was that I had two node_modules directories and in each was the library, and the import always referred to the one I didn't update.

I had one node_modules in the application root, and one in the app folder. It always resolved to the app folder, while IntelliJ's "go to declaration" went to the declaration that was actually there.

For me the solution was to remove the node_modules in the app folder, since I added it by mistake.

It happens fast, because you simply need to type yarn add bla in the wrong location and you already have a node_modules in the wrong location, since yarn doesn't care whether a package.json is there or not (as opposed to npm). If you want to have multiple node_modules, the solution is to always make sure you update and refer to the correct one.

Upvotes: 3

Related Questions