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.

Support `"module": "nodenext"` in `tsconfig.json`

See original GitHub issue

Describe the feature you’d like to request

With TypeScript 4.7 providing ECMAScript Module Support, we can now set this in our tsconfig.json file for the module option:

{
  "compilerOptions": {
    "module": "nodenext",
  }
}

However, Next.js rejects this value, and overwrites it with "esnext".

#36189 did add support for "moduleResolution": "nodenext", but not "module": "nodenext".

Describe the solution you’d like

Add "nodenext" and "node16" to module.parsedValues:

parsedValues: [
  ts.ModuleKind.ES2020,
  ts.ModuleKind.ESNext,
  ts.ModuleKind.NodeNext,
  ts.ModuleKind.Node16,
  ts.ModuleKind.CommonJS,
  ts.ModuleKind.AMD,
]

I figure there may be other changes necessary to make this work, and that the TypeScript version should be bumped to 4.7+ with it.

Describe alternatives you’ve considered

I edited writeConfigurationDefaults.js directly in my node_modules for a local project, and it seemed to work.

Relevant aside: I think the discussion at #32237 is a bug that needs to be resolved before this can work as expected. I still haven’t been able to import files with the .js extension.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
crutch12commented, Nov 21, 2022

Is there some progress on this?

1reaction
kachkaevcommented, Nov 8, 2022

👋 @ctjlewis, you can try playing with https://github.com/kachkaev/njt/pull/186 where I attempt to switch a small Next.js 13 project to pure ESM with native Node module resolution. I need to use these two workarounds and it’d be great to see them implemented in Next: https://github.com/vercel/next.js/discussions/41189#discussioncomment-4026895. I’m also unable to use "module": "NodeNext" as mentioned in this issue.

Keeping Next.js aligned with native Node module transpiling and resolution helps keep scripts or tests alongside the app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

module - TypeScript: TSConfig Option
TSConfig. module. Sets the module system for the program. ... the node16 and nodenext modes integrate with Node's native ECMAScript Module support.
Read more >
node.js - Why we need "nodenext" typescript compiler option ...
0-beta, with tsconfig.json containing module set to nodenext . A file with .cts is not being compiled to .cjs , neither ...
Read more >
Dynamic imports are only supported when the 'module' flag is ...
... are only supported when the '--module' flag is set to 'es2020', 'esnext' or 'commonjs'", set the `module` option to `esnext` in your...
Read more >
TypeScript and native ESM on Node.js - 2ality
If you are writing Node.js code, the following settings in tsconfig.json can help: { "compilerOptions": { "module": "NodeNext" ...
Read more >
Understanding TypeScript 4.7 and ECMAScript module support
This will create a tsconfig.json file which contains many options. We will tweak the module option to be nodenext to opt ...
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