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

Linaria crashes with EvalError: Unexpected token 'export' #1242

Closed
nstepien opened this issue May 4, 2023 · 4 comments · Fixed by #1244
Closed

Linaria crashes with EvalError: Unexpected token 'export' #1242

nstepien opened this issue May 4, 2023 · 4 comments · Fixed by #1244
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@nstepien
Copy link
Contributor

nstepien commented May 4, 2023

Environment

  • Linaria version: @linaria/webpack5-loader@4.1.16
  • Bundler (+ version): webpack@5.82.0
  • Node.js version: 20.0.0
  • OS: win11

Description

Linaria crashes with this error with the minimal reproducible demo below:

> webpack

assets by status 1.85 KiB [cached] 1 asset
./main.js 39 bytes [built] [code generated] [1 error]

ERROR in ./main.js
Module build failed (from ./node_modules/@linaria/webpack5-loader/lib/index.js):
D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:355
      throw new EvalError(`${e.message} in${callstack.join('\n| ')}\n`);
      ^

EvalError: Unexpected token 'export' in
| D:\repos\vite-bug\node_modules\clsx\dist\clsx.m.js
| D:\repos\vite-bug\node_modules\react-data-grid\lib\bundle.js
| D:\repos\vite-bug\main.js

    at Module.evaluate (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:355:13)
    at require.Object.assign.ensure (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:295:13)       
    at D:\repos\vite-bug\node_modules\react-data-grid\lib\bundle.js:21:36
    at D:\repos\vite-bug\node_modules\react-data-grid\lib\bundle.js:339:3
    at Script.runInContext (node:vm:134:12)
    at Module.evaluate (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:342:14)
    at require.Object.assign.ensure (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:295:13)       
    at D:\repos\vite-bug\main.js:3:45
    at D:\repos\vite-bug\main.js:7:3
    at Script.runInContext (node:vm:134:12)
    at Module.evaluate (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:342:14)
    at evaluate (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\evaluators\index.js:20:5)
    at evalStage (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\transform-stages\2-eval.js:26:45)
    at syncStages (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\transform.js:47:45)
    at transform (D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\transform.js:146:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

webpack 5.82.0 compiled with 1 error in 865 ms

Reproducible Demo

https://github.com/nstepien/vite-bug/tree/webpack2

  1. Clone the repo above
  2. checkout the webpack2 branch
  3. npm ci
  4. npm run build

What's really odd is that if I update react-data-grid to 7.0.0-beta.29 in this repo, the error goes away and webpack builds fine.
The export error suggest it comes from clsx, but clsx doesn't change.
Only the linaria babel preset has issues with react-data-grid\lib\bundle.js, so I don't think there's anything wrong with the react-data-grid package itself.

@nstepien nstepien 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 May 4, 2023
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels May 4, 2023
@rolftimmermans
Copy link

I ran into this as well. I have a fix here: master...rolftimmermans:linaria:master

If you think this is the right approach I'd be happy to open a PR.

@nstepien
Copy link
Contributor Author

nstepien commented May 4, 2023

@rolftimmermans I tried applying your diff locally, and it didn't seem to fix the error for me 🤔

@Anber
Copy link
Collaborator

Anber commented May 5, 2023

Hi @nstepien!

Thank you for the report! It appears that the rule in charge of identifying ESM files contained an incomplete regular expression. The issue has been resolved in #1245.

@Anber Anber closed this as completed in 821a681 May 5, 2023
@nstepien
Copy link
Contributor Author

nstepien commented May 5, 2023

Thank you!

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 bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants