turbo icon indicating copy to clipboard operation
turbo copied to clipboard

[WEB-995] Support tsconfig `nodenext`

Open padmaia opened this issue 2 years ago • 7 comments

From SyncLinear.com | WEB-995

PACK-3031

padmaia avatar May 03 '23 21:05 padmaia

It looks like we're nearing Turbo release with 99.7% tests passing, and yet, Turbo is STILL unable to resolve any modules with extensions. I'm getting hundreds and hundreds of errors like:


./packages/site-structure/index.ts:1:0
Module not found: Can't resolve './src/siteStructure.js'
> 1 | import { getSiteStructure } from './src/siteStructure.js';
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2 |
  3 | import type {
  4 |   IPageEntryCollectionPartial,

https://nextjs.org/docs/messages/module-not-found

This is easily resolved with a hack on Webpack's side:

  webpack: (config) => {
    config.resolve.extensionAlias = {
      '.js': ['.js', '.ts', '.tsx'],
    };
    return config;
  },

which is also ridiculous, but at least it works.

wojtekmaj avatar Apr 04 '24 09:04 wojtekmaj

this blocks me trying --turbo in nextjs. we use this feature a lot

Jack-Works avatar May 08 '24 06:05 Jack-Works

Would be great if this could be added soon! Can't wait to cut my compile times in half.

At payload we LOVE supporting the latest and greatest next features. And while turbo works, the lack of nodenext support prevents us from running our test suites against turbo, thus we cannot guarantee turbo will work smoothly.

We are using moduleResolution: NodeNext across our entire monorepo, as well as fully-specified imports (that way we can ensure that our packages work outside of bundlers as well). Turbo just errors when it encounters those.

AlessioGr avatar May 29 '24 04:05 AlessioGr

*Sigh* fine, I'll bite.

Introducing next-turbopack-nodenext - a package that patches your Next.js config so that Turbopack could resolve fully specified .js extensions leading to TypeScript files in your src directory.

https://github.com/wojtekmaj/next-turbopack-nodenext

  • Install by executing npm install next-turbopack-nodenext or yarn add next-turbopack-nodenext --dev.
  • Import by adding import withNodeNext from 'next-turbopack-nodenext'.
  • Use it by wrapping your config export default withNodeNext(nextConfig).

wojtekmaj avatar Jul 04 '24 15:07 wojtekmaj

Sigh fine, I'll bite.

Introducing next-turbopack-nodenext - a package that patches your Next.js config so that Turbopack could resolve fully specified .js extensions leading to TypeScript files in your src directory.

https://github.com/wojtekmaj/next-turbopack-nodenext

  • Install by executing npm install next-turbopack-nodenext or yarn add next-turbopack-nodenext --dev.
  • Import by adding import withNodeNext from 'next-turbopack-nodenext'.
  • Use it by wrapping your config export default withNodeNext(nextConfig).

thanks for the effort! however I cannot make it run, is there something in need to add to the next-config (Besides wrapping it with withNodeNext)

i added

experimental: { extensionAlias: [".js"], },

but it did not fix the issue

macrozone avatar Jul 08 '24 11:07 macrozone

@macrozone Not even that should be necessary, unless you're unhappy with the default order the plugin looks for files. If you provide a minimum reproduction I'll be happy to look into this. Also, when you have it, please rather raise an issue against my repo, we don't want to clutter this thread any more than necessary.

wojtekmaj avatar Jul 08 '24 12:07 wojtekmaj

@macrozone Not even that should be necessary, unless you're unhappy with the default order the plugin looks for files. If you provide a minimum reproduction I'll be happy to look into this. Also, when you have it, please rather raise an issue against my repo, we don't want to clutter this thread any more than necessary.

fair point. So far i settled with not using turbo pack in nextjs, until this is officially supported with ESM.

macrozone avatar Jul 08 '24 13:07 macrozone

This PR landed a while back for Turbopack. Will ask Niklas to take a look at the reproduction repo as well.

timneutkens avatar Oct 21 '24 21:10 timneutkens

This should be working now with Next.js 15 (or 15.0.1 for mjs/cjs imports).

mischnic avatar Oct 23 '24 07:10 mischnic

Closing as Turbopack as moved homes

chris-olszewski avatar Nov 05 '24 19:11 chris-olszewski