question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Typescript Node16 Module Resolution (RTK-Query & RTK-Query/React)

See original GitHub issue

Hey RTK Team,

It seems that using Typescript’s Node16 module resolution is incompatible with separate package.json files (which is how RTK does the optional query addon, and that query addon’s React component). With the current setup and node16 set, the two components fail to resovle.

It seems Node16 focuses more on the exports field of the root package.json, and while I’d submit a PR if I was more familiar with the inner-workings of this repo (and with module resolution as a whole) and more confident that this would not break things, I was able to fix the problem by adding the following to package.json:

"exports": {
    "./query/react": "./dist/query/react/index.js",
    "./query": "./dist/query/index.js",
    ".": "./dist/index.js"
  },

(It seems types are automatically inferred from those paths)

Thanks all for the awesome library!

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
phryneascommented, Jul 4, 2022

This would unfortunately be a breaking change for most other environments - so we will not be able to do that before we release a new major version.

In the meantime, the best you can do is import from dist if nothing else works.

1reaction
yukiyokotanicommented, Nov 16, 2022

@phryneas Thank you very much. I solved the problem by declaring module @reduxjs/toolkit/query/react and @reduxjs/toolkit/query.

declare module '@reduxjs/toolkit/query/react' {
  export * from '@reduxjs/toolkit/dist/query/react';
}

declare module '@reduxjs/toolkit/query' {
  export * from '@reduxjs/toolkit/dist/query';
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Usage With TypeScript - Redux Toolkit
This page provides details for using APIs included in RTK Query with TypeScript and how to type them correctly. info. We strongly recommend ......
Read more >
Creating React Apps With Redux Toolkit and RTK Query - Toptal
RTK Query is an advanced data-fetching and client-side caching tool. ... Create React App (CRA) template for use with TypeScript and Redux:
Read more >
Undefined Error when Fetching API using RTK Query React ...
I keep getting this same error of undefined data for multiple components in my data, it was working fine but for some reason...
Read more >
Experimenting with NgRx Store and RTK Query
Developer experience focused and built with TypeScript. RTK Query is also framework-agnostic, which means it can integrate into any framework.
Read more >
@reduxjs/toolkit - npm
Redux Toolkit is available as a package on NPM for use with a module bundler or in a Node application: # NPM npm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found