Skip to content

Cannot find module 'react-toastify' with TypeScript moduleResolution: "NodeNext" #843

@IronGeek

Description

@IronGeek

Do you want to request a feature or report a bug?
Bug

What is the current behavior?

When importing react-toastify in a typescript project with moduleResolution sets to Node16 or NodeNext the following message is shown:

Cannot find module 'react-toastify' or its corresponding type declarations.ts(2307)

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/react-toastify-nodenext-rrxbgm?file=/src/index.tsx

What is the expected behavior?
Typescript should correctly resolve types declaration for react-toastify

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
[email protected]
[email protected] (with moduleResolution: "Node16" or "NodeNext")
[email protected]
[email protected]
[email protected]

Notes
With moduleResolution: "Node16" typescript will ignore the main/ types / typings field in package.json IF exports field is defined. The types declaration file, if needed, should be specified using the exports field, for example:

exports: {
  ".": {
      "types": " ./dist/index.d.ts",
      "require": "./dist/react-toastify.js",
  ...
  }
}

ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing

Metadata

Metadata

Assignees

Labels

Merged in nextMerged but not livebugdependenciesPull requests that update a dependency file

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions