Skip to content

(RTK Alpha 2): Cannot resolve types when moduleResolution is set to node16 #3202

@eric-crowell

Description

@eric-crowell

A follow up on #2485. When importing anything from @reduxjs/[email protected], typescript cannot resolve types when tsconfig.json's moduleResolution is set to node16 or nodenext.

I found that adding the extension .js to the declaration imports resolved the issue. For example....

In my file: ./node_modules/@reduxjs/toolkit/dist/index.d.ts
export { createSlice, } from './createSlice'; -> export { createSlice, } from './createSlice.js';

Two suggestions for a fix: First, maybe the easiest, is add a post build script to add the extensions to the output. Or second, a search and replace to add the extensions to the all the relevant source files. Want to get some thoughts on a direction before attempting a PR. Maybe there's a better way.

I tried looking to see if typescript can just add them while compiling... but didn't find anything that could.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions