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 next.js 13 #280

Closed
Tracked by #1723
vpontis opened this issue Oct 25, 2022 · 18 comments
Closed
Tracked by #1723

Support next.js 13 #280

vpontis opened this issue Oct 25, 2022 · 18 comments

Comments

@vpontis
Copy link

vpontis commented Oct 25, 2022

I believe this doesn't work with Next.js 13 w/ the following config:

  experimental: {
    appDir: true,
  },

I get the following error re Webpack:

ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration[0].module.rules[3] should be one of these:
   ["..." | object { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }, ...]
   -> A rule.
   Details:
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be an instance of RegExp.
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be a string.
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be an instance of function.
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be an object:
      object { and?, not?, or? }
      -> Logic operators used in a condition matcher.
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be an array:
      [RegExp | string | function | object { and?, not?, or? } | [(recursive), ...], ...]
      -> A list of rule conditions matching an absolute path.
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be one of these:
      RegExp | string | function | object { and?, not?, or? } | [(recursive), ...]
      -> A condition matcher matching an absolute path.
    * configuration[0].module.rules[3].oneOf[6].include.or[3] should be one of these:
      RegExp | string | function | object { and?, not?, or? } | [(recursive), ...]
      -> A rule condition matching an absolute path.
    at validate (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/compiled/schema-utils3/index.js:1:150822)
    at validateSchema (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/compiled/webpack/bundle5.js:28:1389593)
    at create (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/compiled/webpack/bundle5.js:28:1435054)
    at webpack (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/compiled/webpack/bundle5.js:28:1435691)
    at Object.f [as webpack] (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/compiled/webpack/bundle5.js:28:874364)
    at HotReloader.start (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/server/dev/hot-reloader.js:460:44)
    at async DevServer.prepare (/Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/server/dev/next-dev-server.js:515:9)
    at async /Users/victor/Code/luma/node_modules/.pnpm/next@13.0.0_mk5yftg2men2cn3ayx4t7ddtvy/node_modules/next/dist/cli/next-dev.js:246:13 {
  errors: [
    {
      keyword: 'oneOf',
      dataPath: '[0].module.rules',
      schemaPath: '#/properties/rules/oneOf',
      params: [Object],
      message: 'should match exactly one schema in oneOf',
      schema: [Array],
      parentSchema: [Object],
      data: [Array],
      children: [Array]
    }
@nicosh
Copy link

nicosh commented Oct 26, 2022

Also now that next.js 13 has introduced turbopack as the new successor to Webpack i'm wondering if next-transpile-modules will keep able to transpile modules, even because at the moment turbopack is available only on dev mode but i guess in the near future will be the default next.js bundler.

@martpie
Copy link
Owner

martpie commented Oct 26, 2022

Hello there, I haven't fully watched Next.js conf, but I roughly saw the new bundler announcement.

I should definitely have a look at this, and see if we can access (and edit!) the Turbopack config from next.config.js. If yes, I am pretty we should be able to make it work. :)

Would have been cool to have a heads up from the official team prior to the release though.

@nicosh
Copy link

nicosh commented Oct 26, 2022

Would have been cool to have a heads up from the official team prior to the release though

This.
Even better they should make you a hiring proposal 🙂, i dont understand why while next.js keeps building (or acquiring) its own tools (especially about monorepos) we still need to use third parties plugins for have a real monorepo architecture.

@vpontis
Copy link
Author

vpontis commented Oct 26, 2022

Thank you @martpie! This is such an awesome package :)

@timneutkens
Copy link

Hey, just a heads up Next.js 13 has a dedicated option called transpilePackages that is somewhat equivalent to next-transpile-modules, you can check the docs here: https://beta.nextjs.org/docs/api-reference/next.config.js#transpilepackages. I've sent a message to the docs team to update the stable docs and upgrade guide to mention this config as well as it applies to both pages and app.

I think next-transpile-modules can now be deprecated (but it's not my decision ofcourse), @martpie wanted this as a built-in option for a long time and we made it happen 🙏

Thanks for maintaining this package for quite some time @martpie, it had quite some usage which is why the built-in option made sense. Another reason is that Next.js 13 changes the compilation of packages/modules quite a bit to support React Server Components.

@martpie
Copy link
Owner

martpie commented Oct 26, 2022

Hi Tim!

That's awesome to hear, I gotta try this new option, and if it's a perfect replacement, then we should definitely (and happily!) deprecate next-transpile-modules 🥳

@Fawwaz-2009
Copy link

in my case the new transpilePackages option alone was not enough, seeing errors that a custom loader is needed. But using both transpilePackages and next-transpile-modules fixed the issue

module.exports = withTM({
    experimental: { transpilePackages: ["package1", "package2"] },
  });

@martpie
Copy link
Owner

martpie commented Oct 27, 2022

Some update: got a lot on my plate for work right now, but I'll be working on that this weekend. Sorry for the wait, we're all excited about Next.js 13 😊

@timneutkens
Copy link

in my case the new transpilePackages option alone was not enough, seeing errors that a custom loader is needed.

This is not super helpful in resolving what you ran into, can you create a reproduction and open an issue on the Next.js repository.

@martpie
Copy link
Owner

martpie commented Oct 29, 2022

cf. #281 for wip.

@martpie martpie mentioned this issue Oct 29, 2022
5 tasks
@martpie martpie pinned this issue Oct 29, 2022
@max-sym
Copy link

max-sym commented Oct 31, 2022

@Fawwaz-2009 #280 (comment)
It brings back the error that the OP mentioned in my case.

@martpie
Copy link
Owner

martpie commented Nov 1, 2022

Fixed in next-transpile-modules@10.0.0, cheers!

@martpie martpie closed this as completed Nov 1, 2022
@martpie
Copy link
Owner

martpie commented Nov 1, 2022

Side note: app dir is experimental, use with caution!

@oalexdoda
Copy link

Anybody else having issues using hooks in transpiled components in Next 13 + next-transpile-modules?

@martpie
Copy link
Owner

martpie commented Nov 1, 2022

Can you open an issue and / or create a reproduction?

@karanshah229
Copy link

@timneutkens @martpie @here
Any idea on timelines as to when transpilePackages will become stable.
We want to use it in a production application but are hesitant since it's in the experimental phase as of now.

@timneutkens
Copy link

@karanshah229 In 13.1, can't share a time yet. We're not planning additional changes to it so should be fine to use and switch over the flag once 13.1 is out.

@martpie
Copy link
Owner

martpie commented Dec 7, 2022

@karanshah229 I would recommend switching now.

Yes it's experimental, but it's only a build step thing, if it does not work for you you will see it before your app is deployed to prod, and you will likely not run into any runtime issue (unless you use it to make package IE11 compatible, a thing you should NOT do).

I have personally tested all recommended setups and they are all working great with transpilePackages, and I am preparing an official deprecation for soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants