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.

Typescript issue with `moduleResolution: NodeNext`

See original GitHub issue

Expected 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

  1. Add .js externsion for all files in source code
  2. Use tools like rollup=plugin-dts to bundle a .d.mts declaration file for auto.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:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dangreencommented, Aug 29, 2022

@kurkle @LeeLenaleee I will research this issue soon.

0reactions
Mister-Hopecommented, Aug 29, 2022

From the typescript docs its not obvious if imports pointing to a directory would read the index.d.(m|c)ts or does it need to be explicit too?

For the latest moduleResolution NodeNext, yes, because in esm package you do have to use

import a from './dir/index.js';

And import a from './dir' or import a from './dir/' do not work. So typescript is asking the samething in nodenext or node16 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 or pnpm patch or patch-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.

Read more comments on GitHub >

github_iconTop 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 >

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