-
Notifications
You must be signed in to change notification settings - Fork 382
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
@lingui/macro has undeclared dependency on @lingui/react #936
Comments
Lingui macro could be used on node environments where react is not required. I'm not sure how to fix this. Any recommendation? |
We could add as peerDependency react but i'm worried about because on newer npm peerDependencies will be auto-downloaded so a lot of node projects will install react without the need |
Yes I have this problem two... react usage must be removed from macro codes |
The project currently can't be used at all without @lingui-react and react, so any project that actually uses it must be using react too. Personally, I'd love to use macros, but my project doesn't use react. So if possible, I'd prefer it if the react portion was optional or moved to a dedicated, separate package. |
After some investigation I found that the I created this commands:
import { t } from "@lingui/macro"
const SOME_CODE = {
hi: t`example`
} And after running |
I use:
with the browserify / tsify / babelify pipeline converting from typescript to browser-ready code. {
"compilerOptions": {
"target": "esnext",
"moduleResolution": "node",
"module": "es6",
"allowJs": true,
"strict": true,
"isolatedModules": true,
"esModuleInterop": true
}
} (plus project-specific paths for {
"presets": ["@babel/env", "@babel/typescript"],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
["polyfill-regenerator", { "method": "usage-pure" }]
]
} If I use: import { t } from '@lingui/macro'
const SOME_CODE = {
hi: t`example`
} and add
So I do have to install react, I can't compile without it being installed. I do understand that using |
Correction: the dependency is on |
Couldn't be the problem browserify or tsfiy doens't handle correctly yet I can compile perfectly with tsc your code, so.. |
I didn't have time until now to investigate further. The difference between your test and my setup is a specific flag that {
"compilerOptions": {
// ...
/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
// ...
} See the
If you set that to the default Starting from your example: $ tsc # no errors
$ sed -i '' -e 's/"skipLibCheck": true, /"skipLibCheck": false,/' tsconfig.json # disable skipLibCheck
$ tsc
node_modules/@lingui/macro/index.d.ts:1:61 - error TS2307: Cannot find module 'react' or its corresponding type declarations.
1 import type { ReactElement, ComponentType, ReactNode } from "react"
~~~~~~~
node_modules/@lingui/macro/index.d.ts:2:40 - error TS2307: Cannot find module '@lingui/core' or its corresponding type declarations.
2 import type { MessageDescriptor } from "@lingui/core"
~~~~~~~~~~~~~~
node_modules/@lingui/macro/index.d.ts:3:39 - error TS2307: Cannot find module '@lingui/react' or its corresponding type declarations.
3 import type { TransRenderProps } from "@lingui/react"
~~~~~~~~~~~~~~~
Found 3 errors. |
I've doing some investigation and you're right that with 1º From our side we could publish inside macro package a global.d.ts file without dependencies of react, or @lingui/react just @lingui/core. Next.js does something similar, so probably this could be a good option. What do you think @mjpieters |
I don't really have much of an opinion on how this is solved, sorry. :-) I'm still green around the ears when it comes to NPM / typescript packaging options. |
I'll fix this in the next tuesday release, we'll going to do that create a node.d.ts types for node environments where react is not included, and if someone is using node environments only has to create that lingui-env.d.ts file or modifiying types: [] on tsconfig pointing that node.d.ts file |
Note that I'm targeting the browser, but am just not using react. Targeting the "no react" version to be the same as "node only" may be confusing for others in the same situation. |
Yes probably I'll call it global.d.ts, because should work in any environment |
Describe the bug
You can't use
@lingui/macro
without installing react, because packages/macro/index.d.ts pulls inreact
and@lingua/react
:js-lingui/packages/macro/index.d.ts
Lines 1 to 3 in 4ad90d4
However, the dependencies are not listed in package.json.
To Reproduce
Install
@lingui/core
and@lingui/macro
, but no other packages into a (pure) TypeScript project and try to use:Expected behavior
Either the dependency should be made clear or the package should be usable without react.
Additional context
Add any other context about the problem here.
lingui --version
: 3.3.0The text was updated successfully, but these errors were encountered: