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.

Trying to make it work with babel-preset-env

See original GitHub issue

Babel-env let you determine the plugins and polyfills you need based on your targeted browser, which is really cool https://github.com/babel/babel/tree/master/experimental/babel-preset-env

But I’m having a hard time trying to make it work with universal-import.

If I use a conventional .babelrc file like this, it works perfectly:

{ 
  "presets": ["es2015", "react", "stage-2"], 
  "plugins": [["emotion", { "inline": true }], "universal-import"], 
  "env": { 
    "development": { 
      "plugins": ["react-hot-loader/babel"] 
    } 
  } 
} 

But when I switch to babel-env, universal-import fails to transpile the imports: screen shot 2017-10-10 at 18 22 13

This is my current .babelrc:

{
  "env": {
    "devClient": {
      "presets": [
        ["env", {
          "targets": { "browsers": ["android >= 4.4", "ios_saf > 9", "and_chr >= 56"] },
          "useBuiltIns": "usage"
        }],
        "react"
      ],
      "plugins": [["emotion", { "inline": true }], "universal-import", "react-hot-loader/babel"],
    },
    "devServer": {
      "presets": [
        ["env", {
          "targets": { "node": "current" }
        }],
        "react"
      ],
      "plugins": [["emotion", { "inline": true }], "universal-import"],
    }
  }
}

Any idea?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
luisherranzcommented, Oct 12, 2017

also, I see you’re using emotion–have you tried their extractStatic feature? Would love to see an article about using extracStatic and this setup’s capability to split stylesheets.

Yes. I am migrating a project from nextjs and styled-components to react-universal and emotion 😃

My first step is to use emotion in inline mode and once everything is working try the switch to extractStatic to see if there’s an improvement in performance. As you can see in our babel-env conf, we are not worried about IE11, although I dislike having to use css variables for dynamic styles, instead of javascript variables.

0reactions
faceyspaceycommented, Oct 19, 2017

it was. but you can’t really develop these modern babel-based apps without at least stage 2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel-preset-es2015 -> babel-preset-env - Babel.js
We're super excited that you're trying to use ES2015 syntax, but instead of continuing yearly presets, the team recommends using babel-preset-env.
Read more >
What is @babel/preset-env and why do I need it? - Jakob Lind
The most common way to use Babel is together with a build system such as webpack. When using Babel with a build tool...
Read more >
Babel & preset-env. Compile to environments, not… - codeburst
Babel preset -env is a preset that compiles down to a minimum of ES5 ( preset-es2015 ), but can also take a browser...
Read more >
How babel preset-env, core-js, and browserslistrc work together
Babel can use plugins for transpiling newer JavaScript syntax. Presets instead are collection of plugins. @babel/preset-env is a collection of ...
Read more >
Unable to run a node.js file with @babel/preset-env
I'm trying to run a simple node.js file which needs the @babel/preset-env preset. The moment I run the js file, I get a...
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