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

EvalError error with Vite build and core-js #1247

Closed
nstepien opened this issue May 6, 2023 · 3 comments
Closed

EvalError error with Vite build and core-js #1247

nstepien opened this issue May 6, 2023 · 3 comments
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: rollup 🗞️ Issue is related to rollup bundler 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 6, 2023

Environment

  • Linaria version: @linaria/vite@4.2.11
  • Bundler (+ version): vite@4.3.5
  • Node.js version: 20.1.0
  • OS: win11

Description

With import 'core-js/stable', linaria crashes vite builds:

vite v4.3.5 building for production...
✓ 523 modules transformed.
✓ built in 1.86s
[linaria] URLSearchParams is not defined in
| D:\repos\vite-bug\node_modules\core-js\modules\web.url-search-params.size.js
| D:/repos/vite-bug/node_modules/core-js/stable/index.js
| D:/repos/vite-bug/main.js

file: D:/repos/vite-bug/main.js
error during build:
D:\repos\vite-bug\node_modules\@linaria\babel-preset\lib\module.js:355
      throw new EvalError(`${e.message} in${callstack.join('\n| ')}\n`);
      ^

EvalError: URLSearchParams is not defined in
| D:\repos\vite-bug\node_modules\core-js\modules\web.url-search-params.size.js
| D:/repos/vite-bug/node_modules/core-js/stable/index.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/core-js/stable/index.js:257:1
    at D:/repos/vite-bug/node_modules/core-js/stable/index.js:261: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:1
    at D:/repos/vite-bug/main.js:5: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 async Object.transform (D:\repos\vite-bug\node_modules\@linaria\vite\dist\index.js:110:22)
    at async transform (file:///D:/repos/vite-bug/node_modules/rollup/dist/es/shared/node-entry.js:23524:16)   
    at async ModuleLoader.addModuleSource (file:///D:/repos/vite-bug/node_modules/rollup/dist/es/shared/node-entry.js:23730:30)

Is there any way to opt out of linaria evaluating files in node_modules?

Reproducible Demo

https://github.com/nstepien/vite-bug/tree/vite-linaria-corejs
Clone the repo, checkout the vite-linaria-corejs branch, npm ci
npm run build -> crash

@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 6, 2023
@github-actions github-actions bot added bundler: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler and removed needs: triage 🏷 Issue needs to be checked and prioritized labels May 6, 2023
@yume-chan
Copy link

I have a similar issue with SolidJS.

If there are any event handlers in a Solid component, the compiled file contains a top level call like:

import {delegateEvents as _$delegateEvents} from "/node_modules/.vite/deps/solid-js_web.js?v=4fdea505";

// component code

_$delegateEvents(["click"]);

Linaria shaker doesn't remove this call, causing solid-js/web to be imported, which contains Web only code like accessing window and document.

@nstepien
Copy link
Contributor Author

Still happening, I've updated the branch with the latest version of linaria/vite.

@layershifter
Copy link
Contributor

Please bump to v5, it uses happy-dom to handle such cases with the usage of DOM APIs:

With @linaria/vite@5.0.2:

yarn run v1.22.19
$ vite build
vite v4.4.9 building for production...
✓ 1352 modules transformed.
dist/index.html                   0.36 kB │ gzip:  0.26 kB
dist/assets/index-039f7c8e.css    0.03 kB │ gzip:  0.05 kB
dist/assets/index-b5bdc37d.js   156.39 kB │ gzip: 63.60 kB
✓ built in 5.86s
✨  Done in 6.47s.

@Anber Anber closed this as completed Sep 25, 2023
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: rollup 🗞️ Issue is related to rollup bundler bundler: webpack 📦 Issue is related to webpack bundler needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

No branches or pull requests

4 participants