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

Can't get react-vite-swc example to work - [plugin:vite:react-swc] × failed to invoke plugin on 'Some("/Users/jsimck/Desktop/vite-project-react-swc/src/main.tsx") #2141

Closed
jsimck opened this issue Dec 29, 2024 · 2 comments

Comments

@jsimck
Copy link

jsimck commented Dec 29, 2024

Describe the bug
I wanted to integrate lingui into my own react vite + swc project, but I seem to have the same issues as with current react example.
When I install dependencies and run the application I got following error (with --debug flag):

  VITE v5.4.9  ready in 405 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
  vite:html-fallback Rewriting GET / to /index.html +0ms
  vite:time 16.31ms /index.html +0ms
  vite:resolve 5.53ms /src/main.tsx -> /Users/jsimck/Desktop/js-lingui/examples/vite-project-react-swc/src/main.tsx +0ms
  vite:load 3.05ms [fs] /src/main.tsx +0ms
1:21:25 PM [vite] Pre-transform error:   × failed to invoke plugin on 'Some("/Users/jsimck/Desktop/js-lingui/examples/vite-project-react-swc/src/main.tsx")'

  vite:resolve 0.23ms /@vite/client -> /Users/jsimck/Desktop/js-lingui/examples/vite-project-react-swc/node_modules/vite/dist/client/client.mjs +60ms
  vite:load 0.29ms [plugin] /@react-refresh +57ms
  vite:import-analysis 1.37ms [0 imports rewritten] /@react-refresh +0ms
  vite:transform 4.07ms /@react-refresh +0ms
  vite:time 4.70ms /@react-refresh +69ms
  vite:load 6.53ms [fs] /src/main.tsx +5ms
  vite:load 5.93ms [fs] /@vite/client +1ms
  vite:resolve 0.15ms @vite/env -> /Users/jsimck/Desktop/js-lingui/examples/vite-project-react-swc/node_modules/vite/dist/client/env.mjs +8ms
  vite:import-analysis 1.16ms [1 imports rewritten] node_modules/vite/dist/client/client.mjs +3ms
  vite:transform 1.51ms /@vite/client +3ms
  vite:time 8.29ms /@vite/client +3ms
1:21:25 PM [vite] Internal server error:   × failed to invoke plugin on 'Some("/Users/jsimck/Desktop/js-lingui/examples/vite-project-react-swc/src/main.tsx")'

  Plugin: vite:react-swc
  File: /Users/jsimck/Desktop/js-lingui/examples/vite-project-react-swc/src/main.tsx
  
  vite:time 11.19ms /src/main.tsx +2ms
  vite:load 2.39ms [fs] /node_modules/vite/dist/client/env.mjs +4ms
  vite:import-analysis 0.16ms [no imports] node_modules/vite/dist/client/env.mjs +3ms
  vite:transform 0.54ms /node_modules/vite/dist/client/env.mjs +3ms
  vite:cache [304] /node_modules/vite/dist/client/env.mjs +0ms
  vite:time 0.63ms /node_modules/vite/dist/client/env.mjs +24ms

Babel is working fine. I tried scanning through existing issue but couldn't find any recent solution to this issue.

To Reproduce
Just downloaded the react example and only changed dependencies from next versions to latest version 5.

package.json

{
  "name": "vite-project-react-swc",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "lingui:extract": "lingui extract",
    "preview": "vite preview"
  },
  "resolutions": {
    "@swc/core": "1.5.7"
  },
  "dependencies": {
    "react": "^18.2.0",
    "@lingui/core": "^5.1.2",
    "@lingui/react": "^5.1.2",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@lingui/babel-plugin-lingui-macro": "^5.1.2",
    "@lingui/cli": "^5.1.2",
    "@lingui/swc-plugin": "*",
    "@lingui/vite-plugin": "^5.1.2",
    "@types/react": "^18.0.28",
    "@types/react-dom": "^18.0.11",
    "@vitejs/plugin-react-swc": "3.7.0",
    "typescript": "^4.9.3",
    "vite": "5.4.9"
  }
}

Additional context
The babel version works perfectly.

  • node version: 22.12.0
  • npm version: 10.9.0
  • MacOS 15.2
@maxsalven
Copy link

This works for me with "@swc/core": "1.9.3" (via overrides on pnpm, but presumably resolutions will work for your setup).

@timofei-iatsenko
Copy link
Collaborator

timofei-iatsenko commented Jan 2, 2025

This is an incompatibility between swc_core and version of lingui swc plugin. Please see compatibility section in the plugin's readme. There is also a note in the example's readme that you may have missed.

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

3 participants