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 support unnecessarily forces "esnext" code generation [canary]

See original GitHub issue

Bug report

Describe the bug

Next.js currently forces that the tsconfig.json file in the source directory has a "module" configuration value of "esnext". This causes any uses of TypeScript that share that tsconfig to generate code that uses import and export statements, which are not supported by all tools (such as Node 8).

From my understanding of the module configuration setting, it only affects TypeScript’s code generation, which Next does not use (it even forces noEmit). Rather, Next’s webpack configuration uses TypeScript for typechecking only and Babel for actual code generation.

Therefore, the value of module should be irrelevant to Next.js.

Expected behavior

Next.js should have no opinion about what the module setting is.

System information

  • Version of Next.js: 8.1.1-canary.29

Additional context

This is hitting me in a scenario where my Next app shares a root with some scripts written in TypeScript that I run with ts-node. Because my team’s environment is Node 8, it errors when it sees the code that was generated to have ES6 modules.

I think the same logic applies to the isolatedModules setting, which also seems to only affect TypeScript’s code generation. I’ve had to add import {} statements in my server code that feel unnecessary.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
fionawhimcommented, May 27, 2019

Yep, those are all useful workarounds. But I would be happier if Next.js didn’t require any TypeScript settings it didn’t need, and even if it did need them (like --noEmit) see if they could be moved to Next’s invocation of tsc rather than forcing them into the tsconfig.json file itself.

3reactions
fionawhimcommented, May 30, 2019

@Timer OK. I think we can implement workarounds.

Regardless, thanks for adding in native TypeScript support! This is a huge win for Next and I’m glad that our webapps will be able to adopt it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript support unnecessarily forces "esnext" code ...
From my understanding of the module configuration setting, it only affects TypeScript's code generation, which Next does not use (it even forces ......
Read more >
TSConfig Option: target - TypeScript
The special ESNext value refers to the highest version your version of TypeScript supports. This setting should be used with caution, since it...
Read more >
next - npm
Visit nextjs.org/learn to get started with Next.js. The below readme is the documentation for the canary (prerelease) branch.
Read more >
RubyMine 2019.1 (191.6183.108 build) Release Notes | Knowledge ...
Bug, IDEA-202062, Code generation for equals will reference built-in java classes directly regardless of whether identically named user-defined classes are ...
Read more >
Content Types - ESBuild
Transforming ES6+ syntax to ES5 is not supported yet. However, if you're using esbuild to transform ES5 code, you should still set the...
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