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

If core-js version doesn't happen to resolve to 2, it produces a Babel error #468

Closed
silvenon opened this issue Aug 8, 2019 · 3 comments

Comments

@silvenon
Copy link
Contributor

silvenon commented Aug 8, 2019

Environment

linaria@1.3.1
@babel/preset-env@7.5.5
@babel/cli@7.5.5

Description

Ok, this goes beyond my level of understanding, but let's try.

Linaria depends on core-js@^2.0.0, and the environment where Linaria is being used should also use core-js 2, but that resolution is not necessarily up to the linaria dependency. Linaria also depends on @babel/register^7.0.0, where @babel/register@7.0.0 (without the caret) depends on core-js 2, but @babel/register@7.4.0 depends on core-js 3. This usually doesn't seem to be a problem because in the real world other dependencies seem to ultimately depend on core-js 2, so that's what it resolves to, but Linaria shouldn't rely on that coincidence.

If I have the wrong version of core-js, I get the following Babel error:

{ Error: [BABEL] /Users/silvenon/Code/test/linaria/index.js: Cannot find module 'core-js/modules/es7.array.includes' (While processing: "/Users/silvenon/Code/test/linaria/node_modules/linaria/babel.js")
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at Object.<anonymous> (/Users/silvenon/Code/test/linaria/node_modules/linaria/lib/babel/module.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Module.require (internal/modules/cjs/loader.js:723:19) code: 'MODULE_NOT_FOUND' }

Reproducible Demo

Configure Babel:

// babel.config.js
module.exports = {
  presets: [
    'linaria/babel',
    '@babel/preset-react',
  ],
}

Create a Linaria class name:

// index.js
import { css } from 'linaria'

css`
  color: red;
`

Try to compile it with Babel:

yarn babel index.js

Solution

Temporary solution for people using Linaria:

yarn add core-js@^2

A permanent solution for Linaria might be locking @babel/register to 7.0.0, but I might be off about how module resolution works. 😄

@Daniel15
Copy link
Contributor

Duplicate of #420 I think?

@lu-zen
Copy link

lu-zen commented Sep 15, 2019

@silvenon since babel deprecated their polyfill pkg and recommended people to use core-js directly, I think lots of projects are going to depend on the latest version, which may be a problem since linaria has v2 as a dep =/

@silvenon
Copy link
Contributor Author

I'm fine with whatever core-js version Linaria wants, this issue was about enforcing this, so the user knows what's going on, or preferably doesn't have to.

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

4 participants