Cannot find module or its corresponding type declaration when "main" has cjs file extension #45496
Labels
Needs Investigation
This issue needs a team member to investigate its status.
Milestone
Bug Report
When importing a module that sets
package.json#main = "dist/index.cjs"
,tsc
outputsCannot find module ... or its corresponding type declaration
. Manually renaming the file todist/index.js
and updatingpackage.json#main = "dist/index.js"
fixes it.In Node, using
cjs
extensions for CommonJS output is mandatory when usingpackage.json#type = "module"
. Note that this package has other exports which are not picked up by TypeScript (but could be exploited):Here is my
tsconfig.json
(I am only using TypeScript to check types):Please explain to me what is my mistake. I would be happy to know how to make Node, ESM, and TypeScript work together.
🔎 Search Terms
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about cjs/CommonJS.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
It should not report a missing module error.
The text was updated successfully, but these errors were encountered: