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

Cannot read property 'locale' of null for @lingui/loader #642

Closed
danielkcz opened this issue Apr 11, 2020 · 20 comments
Closed

Cannot read property 'locale' of null for @lingui/loader #642

danielkcz opened this issue Apr 11, 2020 · 20 comments

Comments

@danielkcz
Copy link
Contributor

Describe the bug
App crashes when using @lingui/loader

To Reproduce
Install deps and run example of create-react-app from next branch.

Expected behavior
It should work :)

Additional context
image

It's coming from this line. Apparently the getCatalogForFile returns null for some reason. I will investigate it further, but I suspect it's a classic issue of wrong path separators (I am on Windows).

const { locale, catalog } = getCatalogForFile(

  • jsLingui version lingui --version: 3.0.0-10
@tricoder42
Copy link
Contributor

Unfortunatelly I can't test it on Windows. Let me know what you've found 👍

@danielkcz
Copy link
Contributor Author

danielkcz commented Apr 11, 2020

So it seems the minimatch is a culprit here. Looking at the getCatalogForFile when I have src\locales\{locale}.po in input the resulting regexp is /^(?:src\/locales\/([^\/.]+)\.po)$/ expecting wrong separator and then match fails.

export function getCatalogForFile(file: string, catalogs: Array<Catalog>) {

There is even a long-standing PR in minimatch that probably fixes it along with linked open issues.

I also found path.normalize() in NodeJS which would fix separators in the path, but with minimatch issues it's a lost cause.

It's rather silly that even in 2020 we are still unable to solve this stupid problem in some universal way. I am not that well oriented in NodeJS-verse so I am not sure what are alternatives to minimatch.

@danielkcz
Copy link
Contributor Author

I have found micromatch which seems to be the successor that actually works.

And now I am freaking out because snapshot testing is a huge problem here. All tests are failing for me because of wrong path separators in snapshots :/

@tricoder42
Copy link
Contributor

tricoder42 commented Apr 11, 2020 via email

@danielkcz
Copy link
Contributor Author

Fixed in #643

@panuhorsmalahti
Copy link

I still get this issue with 3.0.0-11. I checked that _getCatalogForFile is null for me (on Windows).

@danielkcz
Copy link
Contributor Author

danielkcz commented Apr 23, 2020

@panuhorsmalahti Can you try to provide a reproduction repo? It works fine for me (also on Windows). Perhaps you have found a different edge case there.

@panuhorsmalahti
Copy link

panuhorsmalahti commented Apr 23, 2020

Yeah, it seems to be a different issue. The catalog glob in the function is a different path from the file:
catalogGlob: locale/*/messages.po
file: src\locales\en\messages.po

And the catalog location for me seems to be default: https://github.com/lingui/js-lingui/blob/next/packages/conf/src/index.ts#L43
I'll try changing that, sec.

EDIT: Got it fixed with this catalog config:

   "catalogs": [
      {
         path: "src/locales/{locale}/messages",
         include: ["<rootDir>"],
         exclude: ["*/node_modules/*"],
      },
  ],

@MartijnHols
Copy link

It doesn't work if you use <rootDir> in your catalog path.

@semoal
Copy link
Contributor

semoal commented Dec 11, 2020

It doesn't work if you use <rootDir> in your catalog path.

Hm with latest versión, should work properly with rootdir, create a new issue if you find this not working properly

@MartijnHols
Copy link

Yes on latest version. It's an easy test too if you're using @lingui/loader; just prepend your catalog paths with <rootDir>/.

@semoal
Copy link
Contributor

semoal commented Dec 12, 2020

Yes on latest version. It's an easy test too if you're using @lingui/loader; just prepend your catalog paths with <rootDir>/.

Alright, I'll take a look then

@semoal
Copy link
Contributor

semoal commented Dec 12, 2020

Yes on latest version. It's an easy test too if you're using @lingui/loader; just prepend your catalog paths with <rootDir>/.

Martijn could you tell me the differences to see the error in our example of create-react-app?
https://github.com/lingui/js-lingui/tree/main/examples/create-react-app

We are using in catalog paths, and @lingui/loader in i18n.ts and works as expected. Probably i'm missing something =)

@ghost
Copy link

ghost commented Jan 30, 2021

@semoal

The project with React https://github.com/lingui/js-lingui/tree/main/examples/create-react-app (examples) does not work. Here is the error in screenshot. Tested on January 30, 2021. The Lingui project has a lot of bugs, to this day even with version 3.4.0, extraction does not work well, compilation does not work well either, production interpolation always returns the name of the variable {var} and the loader (@lingui/loader) returns "TypeError: Cannot read property 'locale' of null". In development mode, the interpolation works well, but when going to production nothing works as expected. There have been many problems related to these contexts, I've gone through the issues a bit but so far (Jan 30, 2021) none of this is fixed.

screenshot-user-images-githubusercontent-com-26247346-106368717-0d7ea500-634c-11eb-983a-6e21ca21674f-png-1612043756103

@semoal
Copy link
Contributor

semoal commented Jan 30, 2021

@semoal @tricoder42

The project with React https://github.com/lingui/js-lingui/tree/main/examples/create-react-app (examples) does not work. Here is the error in screenshot. Tested on January 30, 2021. The Lingui project has a lot of bugs, to this day even with version 3.4.0, extraction does not work well, compilation does not work well either, production interpolation always returns the name of the variable {var} and the loader (@lingui/loader) returns "TypeError: Cannot read property 'locale' of null". In development mode, the interpolation works well, but when going to production nothing works as expected. There have been many problems related to these contexts, I've gone through the issues a bit but so far (Jan 30, 2021) none of this is fixed. Since I installed Lingui, I have only problems and it's a shame not to be able to install it and work without too many complications.

screenshot-localhost-3000-1612041743343

Haha :) I'll conclude with your super useful commentary about Lingui... That Lingui with 150.000 DOWNLOADS MONTHLY, used by the biggest companies and maintained and created for FREE, probably "LINGUI PROBLEMS" are just your problems. Don't be a shame for the community and do something useful for it.

Thanks 👍🏻

ps: a screenshot about create-react-app example with a fresh installation and doing yarn start:

Screenshot 2021-01-30 at 23 03 18

@ghost
Copy link

ghost commented Jan 30, 2021

Does it make sense that it works in some people and not in others? My intention was not to shock you, I'm part of the community myself but just to make you understand that the project works in some people and not in others and it's not normal. If you need a specific configuration, you have to mark it somewhere. For the create-react-app project, I followed the README "yarn install - yarn start" and the page to display this error, I didn't do anything else. Try the version in the "examples" folder.

@semoal
Copy link
Contributor

semoal commented Jan 30, 2021

Does it make sense that it works in some people and not in others? My intention was not to shock you, I'm part of the community myself but just to make you understand that the project works in some people and not in others and it's not normal. If you need a specific configuration, you have to mark it somewhere. For the create-react-app project, I followed the README "yarn install - yarn start" and the page to display this error. Try the version in the "examples" folder.

A lot of projects work for some people and not for others, its normal because programs are made by humans that makes mistakes.

We try to keep Lingui as much as maintained as we can, practically we release a new version each tuesday.

Sincerely i would like to all projects being as good maintained as Lingui is.

About your issue, I think in the next version is fixed(Next tuesday), because we did a minor change to resolve catalogs for snowpack plugin and Will resolve the issue Also for webpack

@ghost
Copy link

ghost commented Jan 30, 2021

That Lingui with 150.000 DOWNLOADS MONTHLY, used by the biggest companies

@semoal Yes you didn't lie but the default actions of lingui if I may say so, are extraction (yarn extract) and compilation (yarn compile). It's different actions must be universal for all users, if a yarn extract works for one user and not for another it's not the same dependency. It was just constructive criticism to get the team to look at the problems and fixes. It's still used by big companies as you say. Peace!

@lgenzelis
Copy link

lgenzelis commented Feb 12, 2021

Hi folks! :) I see that the issue is closed, but I'm observing the exact same behavior reported by @msixc . To reproduce it:

git clone [email protected]:lingui/js-lingui.git
cd js-lingui/examples/create-react-app/
yarn install
yarn start

Screen Shot 2021-02-11 at 9 22 27 PM

(my yarn version is 1.22.10, just in case)

Am I missing some step @semoal ?

@lgenzelis
Copy link

I open a new issue, since this one is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants