TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Cannot find module '@reduxjs/toolkit/query/react'. when "moduleResolution": "node16".

Open uk-taniyama opened this issue 3 years ago • 2 comments

Bug Report

'@reduxjs/toolkit/query/react' has nested package.json. BUT some other package use package.json exports.

🔎 Search Terms

moduleResolution, node16

🕗 Version & Regression Information

Version 4.8.3

💻 Code

import {createApi} from '@reduxjs/toolkit/query/react';

🙁 Actual behavior

"moduleResolution": "Node16" traceResolution

$ tsc --noEmit --traceResolution
File '/tmp/work/src/package.json' does not exist.
Found 'package.json' at '/tmp/work/package.json'.
'package.json' does not have a 'typesVersions' field.
======== Resolving module '@reduxjs/toolkit/query/react' from '/tmp/work/src/index.ts'. ========
Explicitly specified module resolution kind: 'Node16'.
File '/tmp/work/src/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/package.json' exists according to earlier cached lookups.
Loading module '@reduxjs/toolkit/query/react' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/tmp/work/src/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'reduxjs__toolkit/query/react'
Found 'package.json' at '/tmp/work/node_modules/@reduxjs/toolkit/query/react/package.json'.
'package.json' does not have a 'typesVersions' field.
Found 'package.json' at '/tmp/work/node_modules/@reduxjs/toolkit/package.json'.
'package.json' does not have a 'typesVersions' field.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.ts' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.tsx' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'dist/index.d.ts' that references '/tmp/work/node_modules/@reduxjs/toolkit/query/react/dist/index.d.ts'.
Loading module as file / folder, candidate module location '/tmp/work/node_modules/@reduxjs/toolkit/query/react/dist/index.d.ts', target file type 'TypeScript'.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react/index.ts' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react/index.tsx' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react/index.d.ts' does not exist.
Directory '/tmp/work/node_modules/@types' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'reduxjs__toolkit/query/react'
Directory '/tmp/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'reduxjs__toolkit/query/react'
Directory '/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'reduxjs__toolkit/query/react'
File '/tmp/work/src/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/package.json' exists according to earlier cached lookups.
Loading module '@reduxjs/toolkit/query/react' from 'node_modules' folder, target file type 'JavaScript'.
Directory '/tmp/work/src/node_modules' does not exist, skipping all lookups in it.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/@reduxjs/toolkit/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.js' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.jsx' does not exist.
'package.json' has 'main' field 'dist/index.js' that references '/tmp/work/node_modules/@reduxjs/toolkit/query/react/dist/index.js'.
Loading module as file / folder, candidate module location '/tmp/work/node_modules/@reduxjs/toolkit/query/react/dist/index.js', target file type 'JavaScript'.
File name '/tmp/work/node_modules/@reduxjs/toolkit/query/react/dist/index.js' has a '.js' extension - stripping it.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react/index.js' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react/index.jsx' does not exist.
Directory '/tmp/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name '@reduxjs/toolkit/query/react' was not resolved. ========
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist.
Found 'package.json' at '/tmp/work/node_modules/typescript/package.json'.
'package.json' does not have a 'typesVersions' field.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/lib/package.json' does not exist according to earlier cached lookups.
File '/tmp/work/node_modules/typescript/package.json' exists according to earlier cached lookups.
src/index.ts(1,25): error TS2307: Cannot find module '@reduxjs/toolkit/query/react' or its corresponding type declarations.

🙂 Expected behavior

"moduleResolution": "Node" traceResolution

$ tsc --noEmit --traceResolution
======== Resolving module '@reduxjs/toolkit/query/react' from '/tmp/work/src/index.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
Loading module '@reduxjs/toolkit/query/react' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/tmp/work/src/node_modules' does not exist, skipping all lookups in it.
Scoped package detected, looking in 'reduxjs__toolkit/query/react'
Found 'package.json' at '/tmp/work/node_modules/@reduxjs/toolkit/query/react/package.json'.
'package.json' does not have a 'typesVersions' field.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.ts' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.tsx' does not exist.
File '/tmp/work/node_modules/@reduxjs/toolkit/query/react.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field '../../dist/query/react/index.d.ts' that references '/tmp/work/node_modules/@reduxjs/toolkit/dist/query/react/index.d.ts'.
File '/tmp/work/node_modules/@reduxjs/toolkit/dist/query/react/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/tmp/work/node_modules/@reduxjs/toolkit/dist/query/react/index.d.ts', result '/tmp/work/node_modules/@reduxjs/toolkit/dist/query/react/index.d.ts'.
======== Module name '@reduxjs/toolkit/query/react' was successfully resolved to '/tmp/work/node_modules/@reduxjs/toolkit/dist/query/react/index.d.ts' with Package ID '@reduxjs/toolkit-query-react/eact/[email protected]'. ========

uk-taniyama avatar Sep 20 '22 09:09 uk-taniyama

Most likely it should be addressed in RTK package https://github.com/reduxjs/redux-toolkit/issues/2485

IllusionMH avatar Sep 20 '22 13:09 IllusionMH

ok. but.... i dont understand next point.

  • Why and what is the purpose of searching package.json?
  • Why use the unexpected package.json in post-processing?

this package.json is expected.

Found 'package.json' at '/tmp/work/node_modules/@reduxjs/toolkit/query/react/package.json'.
'package.json' does not have a 'typesVersions' field.

this package.json is not expected.

Found 'package.json' at '/tmp/work/node_modules/@reduxjs/toolkit/package.json'.
'package.json' does not have a 'typesVersions' field.

and next pakcage.json is not expected. maybe '/tmp/work/node_modules/@reduxjs/toolkit/package.json'.

'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'dist/index.d.ts' that references '/tmp/work/node_modules/@reduxjs/toolkit/query/react/dist/index.d.ts'.

uk-taniyama avatar Sep 20 '22 14:09 uk-taniyama

This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

typescript-bot avatar Sep 24 '22 10:09 typescript-bot