fnando / i18n

A small library to provide the I18n translations on the JavaScript.
https://fnando.github.io/i18n/
MIT License
169 stars 20 forks source link

Missing Export In Browser Index.js #92

Closed wbotelhos closed 9 months ago

wbotelhos commented 9 months ago

Description

Missing export in browser/index.js

How to reproduce

import { I18n } from 'i18n-js';

What do you expect

Import the I18n.

What happened instead

It's returning void.

Software:

Full backtrace

18:54:16 js.1       | ▲ [WARNING] Import "I18n" will always be undefined because the file "../../node_modules/i18n-js/dist/browser/index.js" has no exports [import-is-undefined]
18:54:16 js.1       | 
18:54:16 js.1       |     modules/i18n.js:1:9:
18:54:16 js.1       |       1 │ import { I18n } from 'i18n-js';
fnando commented 9 months ago

what bundler tool are you currently using?

browser export doesn't have module support, which makes sense. Looks like whatever you're using should be picking up import/require rather than browser.

wbotelhos commented 9 months ago

I'm using esbuild 0.20.0.

Here is my config:

import { I18n } from 'i18n-js';

const locale = document.documentElement.lang;

import en from '@/translations/en.json';
import ptBR from '@/translations/pt-BR.json';
import ru from '@/translations/ru.json';

const i18n = new I18n();

i18n.store(
  {
    'en': en,
    'pt-BR': ptBR,
    'ru': ru,
  }[locale]
);

i18n.enableFallback = true;
i18n.defaultLocale = document.documentElement.dataset.defaultLocale;
i18n.locale = locale;

export default i18n;
fnando commented 9 months ago

oh, this has been covered on the readme. Go to the troubleshooting section. :)

wbotelhos commented 9 months ago

It fixed and another lib @glidejs/glide didn't like it. Maybe I need understand better how all those configs works before upgrade. Any tip here?

19:12:07 js.1       | ✘ [ERROR] No matching export in "../../node_modules/@glidejs/glide/dist/glide.js" for import "default"
19:12:07 js.1       | 
19:12:07 js.1       |     pages/events/views/events/tickets.js:3:7:
19:12:07 js.1       |       3 │ import Glide from '@glidejs/glide';
19:12:07 js.1       |         ╵        ~~~~~
fnando commented 9 months ago

I'll take a look at this tonight.

fnando commented 9 months ago

Ah, looks like we can't assume all packages will export main as a module export. Try moving main further down the list on --main-fields, like --main-fields=module,main,browser

fnando commented 9 months ago

Yep, was able to reproduce this locally. I updated the readme with this new info.

wbotelhos commented 9 months ago

It worked, Nando. Thanks! ❤️

wbotelhos commented 9 months ago

@fnando Unfortunately I got another error, this time it comes from Tippy.js. It's not recognizing the var process.

ReferenceError: process is not defined
    at event.debug-b5100f8117412a9eab692445c8a1940819c880ee47994a770182f1836e8a0846.js:56946:1
(anonymous) @ event.debug-b5100f8117412a9eab692445c8a1940819c880ee47994a770182f1836e8a0846.js:56946

It happens during the import:

import tippy from 'tippy.js';

It's on this part of the code:

var visitedMessages;
if (process.env.NODE_ENV !== "production") { <<<
  resetVisitedMessages();
}

I tried the configs:

mainFields: ['module', 'main', 'browser'],

And the:

mainFields: ['import', 'require', 'module', 'main', 'browser'],
fnando commented 9 months ago

Oh, i got this one before. I think you can use something like this: --define:process.env.NODE_ENV="development" (or production) on the esbuild command.

wbotelhos commented 9 months ago

It worked, Nando. Again, thank you!

wbotelhos commented 9 months ago

Hey, @fnando

I'm no sure if I should keep bringing it to this issue, since it can be outside this lib scope. Let me know if it does not make sense from now on.

I found another problem with tippyjs:

RangeError: Maximum call stack size exceeded
    at getWindow (system.debug-faf277173fc11b1de6a001ffccc0787d888b747577cb92cdc1b2d61e49d22bb3.js:26806:19)
    at getComputedStyle (system.debug-faf277173fc11b1de6a001ffccc0787d888b747577cb92cdc1b2d61e49d22bb3.js:26999:10)

Looks like there is an issue related to it. For now I'll rollback and wait for a better time to upgrade just it.

fnando commented 9 months ago

I'm thinking about reverting the package.json change because it broke too many projects, unfortunately. 🫠

fnando commented 9 months ago

Just released v4.4.3-beta.0. Can you please give it a try and report back? Thanks!

wbotelhos commented 9 months ago

Now It's working correctly. Hope you can find a full supported solution in the future. Thanks!

fnando commented 9 months ago

just released v4.4.3