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

Broken build when using react-redux #1226

Closed
PierreGUI opened this issue Mar 14, 2023 · 8 comments · Fixed by #1231
Closed

Broken build when using react-redux #1226

PierreGUI opened this issue Mar 14, 2023 · 8 comments · Fixed by #1231
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

@PierreGUI
Copy link

Environment

"@linaria/react": "^4.3.6",
"@linaria/core": "^4.2.8",
"@linaria/webpack-loader": "^4.1.15",
"webpack": "^5.76.1",

Description

Using react-redux and Linaria breaks build: EvalError: (0 , _batch.setBatch) is not a function in ...

Reproducible Demo

https://stackblitz.com/edit/linaria-bug-ekrflt?file=src/index.jsx

@PierreGUI PierreGUI 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 14, 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 Mar 14, 2023
@PierreGUI
Copy link
Author

I tried a whole new setup with Vite, but the build also fails when dealing with react-redux wrapped components:

EvalError: (0 , _useSelector.initializeUseSelector) is not a function in
| /node_modules/react-redux/es/index.js
    at Module.evaluate (/node_modules/@linaria/babel-preset/lib/module.js:355:13)
    at require.Object.assign.ensure (/node_modules/@linaria/babel-preset/lib/module.js:295:13)

@PierreGUI
Copy link
Author

I've tried to find earlier versions of Linaria or Babel that would compile the reproduction repo.

  • I went back all the way to my current configuration: Linaria 2 (supports babel/core 7.13 max) ✅
  • Also, Linaria 3 (airbnb) builds successfully (latest babel) ✅ (sample repo)
  • Starting from Linaria 4, I run into the issue documented above (I tried different babel versions) ❌

@Anber
Copy link
Collaborator

Anber commented Apr 24, 2023

Hi @PierreGUI!

This #1237 should fix it.

@PierreGUI
Copy link
Author

I built Linaria locally and I confirm it fixes my issue. Thank you so much!

@PierreGUI
Copy link
Author

    "@babel/preset-react": "7.12.13",
    "@linaria/babel-preset": "4.4.5",
    "@linaria/core": "4.2.10",
    "@linaria/shaker": "^4.2.11",
    "@linaria/webpack-loader": "4.1.17",

After the latest update, this error came back:

ERROR in ./Parent.view.tsx
Module build failed (from ./node_modules/@linaria/webpack5-loader/lib/index.js):

EvalError: (0 , _batch.setBatch) is not a function in
| ./node_modules/react-redux/es/index.js
| ./Component.redux.ts
| ./Parent.view.tsx
    at Module.evaluate (./node_modules/@linaria/babel-preset/lib/module.js:355:13)
    at require.Object.assign.ensure (./node_modules/@linaria/babel-preset/lib/module.js:295:13)
    at Script.runInContext (node:vm:139:12)
    at Module.evaluate (./node_modules/@linaria/babel-preset/lib/module.js:342:14)

Unfortunately I'm unable to reproduce it in isolation.

@PierreGUI
Copy link
Author

PierreGUI commented Jun 20, 2023

@Anber sorry to bother you, I can't reopen this issue I but I have a reproduction case now.
It happens only with these version of npm packages, I tried the latest react-redux v8 but then new errors appear. I didn't get v8 to work on my codebase yet so that's based on latest v7: https://stackblitz.com/edit/linaria-bug-qyfnwu?file=src%2Findex.jsx

Would really appreciate if you could have a look, thanks 🙏

PS: for v8 repro case just fork this project and bump react-redux, the error is similar to the one above initializeUseSelector not a function

@Anber
Copy link
Collaborator

Anber commented Jul 6, 2023

Hi @PierreGUI!

I've found the reason why it doesn't work with v7. I made a fix here #1274 and will merge it as soon as I fix all tests.

@PierreGUI
Copy link
Author

Thanks @Anber!
Using the shaker from your branch, my entire codebase builds 🎉

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.

2 participants