question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document compatibility steps for Vite integration

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:22 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
a1oohacommented, Jul 14, 2022

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.

3reactions
semoalcommented, Feb 12, 2021

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… #951

I’ll release the next tuesday anyways a new version with ESM shipping =)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found