Typescript issue with `moduleResolution: NodeNext`
See original GitHub issueExpected behavior
node_modules/.pnpm/chart.js@3.9.1/node_modules/chart.js/auto/auto.mts(1,23): error TS2307: Cannot find module '../types/index.esm' or its corresponding type declarations.
Current behavior
Cuurently chart.js 's declaration files can not work with moduleResolution: NodeNext
when targeting esm.
(Both with chart.js
and chart.js/auto
)
I think that al least chart.js/auto
should respect latest typescript requirements on esm.
See https://www.typescriptlang.org/docs/handbook/esm-node.html for more details. This is somthing ts adds support in 4.7
Reproducible sample
Not related to chart runtime code
Optional extra steps/info to reproduce
No response
Possible solution
- Add
.js
externsion for all files in source code - Use tools like
rollup=plugin-dts
to bundle a.d.mts
declaration file forauto.mts
to avoid a relative import without extension instead of creating a declaration wrapper.
Context
No response
chart.js version
all chart.js version are having this issue
Browser name and version
No response
Link to your project
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
"moduleResolution": "NodeNext" throws ESM related errors ...
The main issue with ESM and nodenext / node16 mode is TypeScript refusing to add .js extensions to the generated import statements in...
Read more >Documentation - Module Resolution - TypeScript
If you are having resolution problems with import s and export s in TypeScript, try setting moduleResolution: "node" to see if it fixes...
Read more >node.js - Why we need "nodenext" typescript compiler option ...
module and moduleResolution. The first thing that needs clarification is the difference the module and moduleResolution compiler options.
Read more >Add file extension when '--moduleResolution' is 'node16' or ...
TypeScript 4.7: ECMAScript Module Support: Add file extension when '--moduleResolution' is 'node16' or 'nodenext'. Relates to 1. Relates to 1 issue (0 ...
Read more >tsc-esm-fix - npm
meta is not allowed. esbuild/1043: empty output for interface files that breaks reimport. moduleResolution: nodenext. Nightly build TypeScript ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kurkle @LeeLenaleee I will research this issue soon.
For the latest moduleResolution
NodeNext
, yes, because in esm package you do have to useAnd
import a from './dir'
orimport a from './dir/'
do not work. So typescript is asking the samething innodenext
ornode16
in source code and declaration files( because declaration files could be source code while using by outher files).Since we are outputing esm bundle in 3.9, I was thinking we’d better to convert the exisiting code to a valid esm code in typescript.
But as you are mentioning v4, I looked at the main branch, if you are planing to release v4 very soon (I probably mean in 30 days) I think we can make the changes only in v4, and make a depercated message in 3.9 esm bundle to tell users it’s broken.
It’s not very hard to make a workaround though
yarn patch
orpnpm patch
orpatch-packages
(for npm) for users like me.If anyone meets the same issue and needs a workaround, I would be happy to leave some pieces here.