vscode shows error on dynamic imports when moduleResolution is NodeNext

148 Views Asked by At

In my project I use a library that uses package.json exports, so I have to use "NodeNext" module resolution for TypeScript. Everything is fine but dynamic imports for React.lazy.

const Home = React.lazy(() => import('home'));
                                        ^-------- vscode error here

Cannot find module 'home' or its corresponding type declarations.

When I build/compile the project It looks like that the compiler does find the module but shows another error:

TS2322: Type 'Promise<{ default: typeof import("...\src\home\index"); }>' is not assignable to type 'Promise<{ default: ComponentType; }>'. Type '{ default: typeof import("...\src\home\index"); }' is not assignable to type '{ default: ComponentType; }'. Types of property 'default' are incompatible. Type 'typeof import("...\src\home\index")' is not assignable to type 'ComponentType'.

Note that I use export default in that component file. When I switch to "Node" module resolution this problem solves but those imports of that library which uses package.json exports don't resolve.

0

There are 0 best solutions below