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.

Make it easy to opt out of next/babel preset components

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

Sometimes the provided babel plugins conflict with what I want to do. For example, I would like to use class instead of className and Preact with Next.js.

However, styled-jsx’s babel plugin is overwriting my classes:

image

since I use Tailwind instead of styled-jsx, I would like to turn the styled-jsx plugin off.

There is an old issue to opt out of styled-jsx, but this no longer works since plugins are no longer self identifying:

GitHub Source

You cant simply do myPreset.plugins.filter any more because there is no identifying name for the plugins. You can’t rely on order because the order varies depending on env.

in order to do what i need i am having to copy out the entire source of the babel plugin in order to delete the specific plugin I need.

Describe the solution you’d like

I would like a simple way to opt out of the babel plugins. I think the best way is to simply attach the name of the plugin to each plugin, so that the user can filter in a babel.config.js:

// note: this is just my proposal - this doesnt actually work bc plugins arent self identifying
const nextbabel = require("next/babel");

const wrapNextBabel = (api) => {
  const temp = nextbabel(api);
  temp.plugins = templ.plugins.filter(plugin => plugin.name !== 'styled-jsx')
  return temp;
};
return {
  presets: [wrapNextBabel],
  plugins: [],
};

(btw - Next.js’ typescript fails when you use babel.config.js as oppose to .babelrc - i ended up routing .babelrc to a babel-preset.js in order to trick Next.js)

Describe alternatives you’ve considered

maintaining this ugly ass fork haha

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sw-yxcommented, Apr 7, 2020

ahh you’re right. i accidentally left some in there when i copied some boilerplate.

0reactions
timneutkenscommented, Apr 7, 2020

but i think its also good to no-op styled-jsx when it is not used. could potentially save a lot of kb in wasteful generated classnames.

This should be the case already if you don’t use styled-jsx though. Maybe you have a <style jsx> somewhere 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make it easy to opt out of next/babel preset components #23922
I would like a simple way to opt out of the babel plugins. I think the best way is to simply attach the...
Read more >
Advanced Features: Next.js Compiler
If you have an existing Babel configuration or are using unsupported features, your application will opt-out of the Next.js Compiler and continue using ......
Read more >
Options - Babel.js
Primary options. These options are only allowed as part of Babel's programmatic options, so they are primarily for use by tools that wrap...
Read more >
Parsing error : Cannot find module 'next/babel' - Stack Overflow
Create a workspace config; Specify folders where you need ESLint to run. You can do this easily from VSCode. The net result (following...
Read more >
Using Non-SSR Friendly Components with Next.js
How to disable SSR for Non-SSR Friendly Components in Next.js ... export default Hello ... To make this easier, a utility function can...
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