Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "module": "nodenext" in tsconfig.json #37525

Closed
michaelhays opened this issue Jun 7, 2022 · 6 comments · Fixed by #44177
Closed

Support "module": "nodenext" in tsconfig.json #37525

michaelhays opened this issue Jun 7, 2022 · 6 comments · Fixed by #44177
Labels
TypeScript Related to types with Next.js.

Comments

@michaelhays
Copy link

michaelhays commented Jun 7, 2022

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.

@balazsorban44 balazsorban44 added the TypeScript Related to types with Next.js. label Jun 14, 2022
@jakubmazanec
Copy link

Also, "moduleResolution": "node16" isn't supported, only "node", "node12" or "nodenext".

@terenceodonoghue
Copy link

Are there plans to support it? I'm trying to use a local ES module in my monorepo but it won't resolve without "node16". Even an option to stop Next.js forcibly overwriting the tsconfig.json would be helpful.

@ctjlewis
Copy link
Contributor

@terenceodonoghue Can you post a Replit repro?

@kachkaev
Copy link
Contributor

kachkaev commented Nov 1, 2022

👋 @ctjlewis, you can try playing with kachkaev/njt#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: #41189 (comment). 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.

@crutch12
Copy link

Is there some progress on this?

@kodiakhq kodiakhq bot closed this as completed in #44177 Jan 28, 2023
kodiakhq bot pushed a commit that referenced this issue Jan 28, 2023
## ESM: support module option for tsconfig.json 

- fixes #37525
- fixes #41961

With [TypeScript 4.7 providing ECMAScript Module Support](https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#ecmascript-module-support-in-node-js), we can now set this in our tsconfig.json file for the [module](https://www.typescriptlang.org/tsconfig#module) option.

Webpack added "extensionAlias" to solve importing ts files with .js extension -> webpack/enhanced-resolve#351



Co-authored-by: JJ Kasper <[email protected]>
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TypeScript Related to types with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants