-
Notifications
You must be signed in to change notification settings - Fork 394
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
Vite plugin -> lingui is not a function in new Vite + React + TS project #1449
Comments
That simply because https://stackblitz.com/edit/vitejs-vite-bntf5b?file=package.json We need to ship |
Hi @sven-meyer-wetter-com, the fix is already in the |
@thekip just tried it with the fix locally (on the sample project from the description): npm run dev
> vite-react-typescript-starter@0.0.0 dev
> vite
(node:16015) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
failed to load config from /Users/andrii/Downloads/vitejs-vite-ojqs39/vite.config.ts
error when starting dev server:
/Users/andrii/Downloads/vitejs-vite-ojqs39/node_modules/@lingui/vite-plugin/build/esm/index.js:1
import { getConfig } from "@lingui/conf";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24) |
The "default" export/import is harmful when it comes to ESM/Commonjs interop. if they asked me, I would generally remove it from the standard and discourage everyone of using it. But we have what we have. And other native vite plugins implemented with a default export.
Interesting, it's pointing that you don't have ESM modules enabled in your project. But the StackBlitz example has "type": "module" in the package.json. I changed the pipeline to produce exactly the same output as original's vite-plugin-react produces. So in general it should work. I will take a look. |
@sven-meyer-wetter-com please use a named export in version 3.17.2 |
Describe the bug
I'm trying to get the new vite plugin to work. Babel seems to be setup correctly, extraction works. But when starting the vite dev server, I always get an error saying "lingui is not a function". I followed the docs how to setup and use the vite plugin.
I didn't found an example project how to configure all of this. Is the error maybe caused by a wrong tsconfig configuration?
To Reproduce
I've created an example project on Stackblitz to show the error. It's based on the official Vite + React + TS playground Stackblitz from here (https://vite.new/react-ts).
https://stackblitz.com/edit/vitejs-vite-ojqs39
Expected behavior
No error message, vite dev server is started sucessfully.
Additional context
3.17.1
7.20.12
The text was updated successfully, but these errors were encountered: