Document compatibility steps for Vite integration
See original GitHub issueDescribe the bug
@lingui/core
doesn’t provide a valid ESM package. Thus, it can’t work with Vite, which is an ESM based bundler.
node_modules/@lingui/core/esm/index.js
will import i18nModule
from node_modules/@lingui/core/index.js
. However, node_modules/@lingui/core/index.js
only export module in CJS way instead of in ESM way.
To Reproduce
$ git clone https://github.com/ocavue/lingui-esm-issue.git
$ cd lingui-esm-issue
$ yarn install
$ yarn dev
Open http://localhost:3000 and you can see Uncaught TypeError: Cannot read property 'setupI18n' of undefined
in the console.
Expected behavior
No error occurs.
Additional context
- jsLingui version:
@lingui/core@3.5.1
- Babel version:
@babel/core@7.12.13
- Your Babel config (e.g.
.babelrc
) or framework you use (Create React App, Meteor, etc.): vite
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:22 (15 by maintainers)
Top Results From Across the Web
Building for Production - Vite
Browser Compatibility #. The production bundle assumes support for modern JavaScript. By default, Vite targets browsers which support the native ES Modules, ...
Read more >Plugin API - Vite
If the plugin doesn't use Vite specific hooks and can be implemented as a Compatible Rollup Plugin, then it is recommended to use...
Read more >Getting Started - Vite
Scaffolding Your First Vite Project #. Compatibility Note. Vite requires Node.js version 14.18+, 16+. However, some templates require a higher Node.js version ...
Read more >Features | Vite
Vite provides first-party HMR integrations for Vue Single File Components and React Fast Refresh. There are also official integrations for Preact via ...
Read more >Backend Integration - Vite
If you want to serve the HTML using a traditional backend (e.g. Rails, Laravel) but use Vite for serving assets, check for existing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I wrote a plugin for vite and more, which can compiles messages on the fly! It contains a demo for vite integration in the playground catalogs, Hope this helps.
I’ve just started working on this and got it working sucessfully and we should ship this esm packages… but Lingui at least today won’t work on Vite.
Lingui is a library heavily inspired and created above
babel-plugin-macros
, actually there’s a similar issue for Snowpack integration, so we should decide together an alternative implementation of macros for this new bundlers like vite, esbuild, swc, snowpack… #951I’ll release the next tuesday anyways a new version with ESM shipping =)