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

Plugins presets not applied to defaultLoaders.babel.options #5393

Closed
martpie opened this issue Oct 8, 2018 · 6 comments
Closed

Plugins presets not applied to defaultLoaders.babel.options #5393

martpie opened this issue Oct 8, 2018 · 6 comments

Comments

@martpie
Copy link
Contributor

martpie commented Oct 8, 2018

Bug report

I am not sure if this a Next problem, a Next plugin problem, or a user problem (or maybe a feature?). I am really open to any feedback.

Describe the bug

Similar to #5288. Found when debugging martpie/next-transpile-modules#1

It looks like Next plugins's presets (like next-typescript) are not added to next.config.js's options.defaultLoaders.babel.options.

I have not a lot of knowledge on how Next's build system actually work, but it looks wrong to me. Because of this, Babel won't transpile specified packages in node_modules.

The two solutions (martpie/next-transpile-modules#1 (comment) and martpie/next-transpile-modules#1 (comment)) are in my opinion lame, because the user should not have to worry about it.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. git clone git@github.com:martpie/monorepo-typescript-next-the-sane-way.git
  2. cd monorepo-typescript-next-the-sane-way
  3. npm install
  4. cd website
  5. remove babel.config.js
  6. npm install & npm run dev

Babel will throw an error because it cannot transpile files.

To fix it, you can re-enable the custom babel.config.js or add the following in your next.config.js:

...
webpack(config, options) {
   ...
  options.defaultLoaders.babel.options.presets = [
    '@zeit/next-typescript/babel'
  ];
}

or create a babel.config.js with a similar content

Expected behavior

The user should not have to write a (potentially error prone) babel.config.js or modify the Babel loaders to have this working.

Do you think this should be handled by this plugin or by Next.js (genuine question)? If this is a plugin issue, do you see how this could be automated (how could I get all the presets/plugins used by a user in next.config.js?

Screenshots

System information

  • OS: n/a
  • Browser (if applies) n/a
  • Version of Next.js: 7.0.1

Additional context

n/a

@martpie
Copy link
Contributor Author

martpie commented Jan 29, 2019

Any news on this? I would gladly submit a PR if I knew where to start (and if I knew if it is a bug or an intentional behavior)

(cc @timneutkens)

@timneutkens
Copy link
Member

I'm not really sure I understand the issue here, when adding next-typescript you're required to add the preset to your .babelrc, it might sound nice having Next.js handle that for you automatically, however then you run into issues with other tools that use babelrc / babel to compile being inconsistent, eg jest.

@martpie
Copy link
Contributor Author

martpie commented Jan 29, 2019

You are actually right, I did not notice that you had to create a .babelrc, but this is indeed in the doc, probably a change with Webpack 4 / Babel 7 I did not see.

Then I guess it's on my side to update the documentation of my plugin to make sure people update their .babelrc 🤔

I'll investigate a bit more.

@timneutkens
Copy link
Member

timneutkens commented Jan 29, 2019

🙌 yeah so we changed next-typescript to use the babel preset instead of ts-loader for performance reasons.

@martpie
Copy link
Contributor Author

martpie commented Jan 29, 2019

Then I think we can close this 👍

@martpie martpie closed this as completed Jan 29, 2019
@timneutkens
Copy link
Member

timneutkens commented Jan 29, 2019

🙏 Let me know if you run into any other issues.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants