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

Typescript without React? #1206

Closed
RandomEngy opened this issue Feb 6, 2022 · 7 comments · Fixed by #1367
Closed

Typescript without React? #1206

RandomEngy opened this issue Feb 6, 2022 · 7 comments · Fixed by #1367
Assignees
Milestone

Comments

@RandomEngy
Copy link

There is a React Typescript sample, but it assumes you are using React. There is a Vanilla JS sample, but without TypeScript integration.

I'm a bit confused: do I need Babel? The React example doesn't seem to use it.

I have a minimal project set up here to attempt to get this running without React: https://github.com/RandomEngy/lingui-ts

However when I run lingui extract it errors out:

(node:38396) UnhandledPromiseRejectionWarning: TypeError: ext.match is not a function
    at _callee$ (C:\git\lingui-ts\node_modules\@lingui\cli\api\extractors\index.js:64:21)
    at tryCatch (C:\git\lingui-ts\node_modules\regenerator-runtime\runtime.js:63:40)
    at Generator.invoke [as _invoke] (C:\git\lingui-ts\node_modules\regenerator-runtime\runtime.js:294:22)
    at Generator.next (C:\git\lingui-ts\node_modules\regenerator-runtime\runtime.js:119:21)
    at asyncGeneratorStep (C:\git\lingui-ts\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)
    at _next (C:\git\lingui-ts\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
    at C:\git\lingui-ts\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7
    at new Promise (<anonymous>)
    at C:\git\lingui-ts\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12
    at _extract (C:\git\lingui-ts\node_modules\@lingui\cli\api\extractors\index.js:129:19)
@RandomEngy
Copy link
Author

I've gotten it a little bit further. It turns out the config I needed in package.json was "extractors": ["@lingui/cli/api/extractors/typescript"] . I've extracted the strings to .po files and compiled them to the message.ts file and have set up the initialization.

However, I've got a different error now when I try to build with webpack 5:

ERROR in ./node_modules/resolve/lib/sync.js 3:11-26
Module not found: Error: Can't resolve 'path' in 'C:\git\lingui-ts\node_modules\resolve\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

It looks like it's trying to call some node APIs that aren't available. It looks like lingui has Webpack 5 support so I'm not sure why this is broken.

I see Babel mentioned a lot in the docs but I'm not using Babel to create my JS; it's just done via ts-loader. I also tried adding in Babel, but nothing I tried worked and am unsure how it's supposed to be configured. Can anyone help me figure out what I've got wrong?

@RandomEngy
Copy link
Author

RandomEngy commented Mar 6, 2022

Finally got it working, following steps in https://github.com/Microsoft/TypeScript-Babel-Starter . I had to abandon ts-loader and switch to babel-loader.

Also needed to npm i --save-dev @types/react as there was a type definition in @lingui/macro that was referencing React.

@RandomEngy
Copy link
Author

Now I need to apply it to my project with yarn workspaces and Typescript project references. Before I would just compile with tsc -b but I can't do that with Babel. 😞

I'm wondering if at this point it might be easier to migrate to Lit so I can use their localization library. If anyone is using Lingui successfully with yarn workspaces let me know.

@stale
Copy link

stale bot commented May 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 25, 2022
@RandomEngy

This comment was marked as off-topic.

@stale stale bot removed the wontfix label May 25, 2022
@stale
Copy link

stale bot commented Jul 25, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@thekip
Copy link
Collaborator

thekip commented Feb 14, 2023

Fixed in #1367 would be released as part of v4

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

Successfully merging a pull request may close this issue.

3 participants