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

Compilation error when building CRA project on Linux #745

Closed
livyk opened this issue Mar 31, 2021 · 2 comments
Closed

Compilation error when building CRA project on Linux #745

livyk opened this issue Mar 31, 2021 · 2 comments
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@livyk
Copy link

livyk commented Mar 31, 2021

Environment

  • Linaria version: 3.0.0-beta.1
  • Create React App: 4.0.3
  • Node.js version: 14.16.0
  • OS: Ubuntu 18.04.5

The error is also reproduced when configuring with craco-linaria. The error is also reproducible when configuring with craco-linaria and linaria 2.1.0

Description

I am styling custom React components with styled. Using object spread / rest syntax in props results in a compilation error.
The error message looks like this:

./src/App.tsx
Error: /home/av1at0r/linaria-react-app/src/App.tsx: An unexpected runtime error occurred during dependencies evaluation:
/home/av1at0r/linaria-react-app/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js:1
(function (exports) { import objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
^^^^^^

SyntaxError: Cannot use import statement outside a module
It may happen when your code or third party module is invalid or uses identifiers not available in Node environment, eg. window.
Note that line numbers in above stack trace will most likely not match, because Linaria needed to transform your code a bit.
at transformFile.next (<anonymous>)
at run.next (<anonymous>)
at Generator.next (<anonymous>)

A similar error a similar error occurs when using array spread in a function argument

./src/App.tsx
Error: /home/av1at0r/linaria-react-app/src/App.tsx: An unexpected runtime error occurred during dependencies evaluation:
/home/av1at0r/linaria-react-app/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/slicedToArray.js:1
(function (exports) { import arrayWithHoles from "@babel/runtime/helpers/esm/arrayWithHoles";
^^^^^^

SyntaxError: Cannot use import statement outside a module
It may happen when your code or third party module is invalid or uses identifiers not available in Node environment, eg. window.
Note that line numbers in above stack trace will most likely not match, because Linaria needed to transform your code a bit.

One of the most important details is that the bug is reproducible only on Linux. Build works without problems on Windows.

Reproducible Demo

The master branch demonstrates an error when using object spread / rest.
The error disappears if you make spread not in the props - argument, but in the body of the function.

src/CustomLink.tsx
...
const CustomLink = (props: React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
    const { href, ...rest } = props
...
}

The array-spread branch demonstrates an error when using array spread.
The error disappears if you make spread not in reduce callback - argument, but in the body of the function.

src/cover.ts
...
    return values.reduce((acc, curr) => {
        const key = curr[0];
        const value = curr[1];
        acc[key] = value;
...
}

I would be grateful for information on any way to fix the error without giving up the spread / rest syntax.

@livyk livyk added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Mar 31, 2021
@github-actions github-actions bot removed the needs: triage 🏷 Issue needs to be checked and prioritized label Mar 31, 2021
Anber added a commit that referenced this issue Apr 11, 2021
* fix(babel): better dehydration of jsx-components

* fix(cli): rename cli binary back to "linaria"

* fix(babel): replace babel helpers esm imports with cjs (#745)
@Anber
Copy link
Collaborator

Anber commented Apr 11, 2021

Hi @av1at0r!

Thank you for your report. The fix will be released with 3.0.0-beta.2.

@Anber Anber closed this as completed Apr 11, 2021
@iMoses-Apiiro
Copy link

please update the 2.x version as well, as many people won't be moving to version 3 before it gets out of beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

No branches or pull requests

3 participants