Describe the bug
Crash on Node projects without typescript
To Reproduce
Just use 2.9.0 without typescript installed as peer dependency.
import { Trans } from "@lingui/react"
export default function App() {
return <Trans>This should be translated!</Trans>
}
Expected behavior
Not crash, should be built or something like that.
What's the reason to put typescript as peer dependecy, when a lot of projects don't need typescript for anything.
Shouldn't be built before publish the package? In plain Javascript will work for all the projects.
Hey @semoal, what's the error message please? Could you please the code required to reproduce this error to a repository for quicker debugging?
@FredyC: My guess is that cli loads all modules, including Typescript transformer, and that breaks for projects which doesn't use typescript at all? Before these project get typescript installed without notice.
Hey @semoal, what's the error message please? Could you please the code required to reproduce this error to a repository for quicker debugging?
@FredyC: My guess is that cli loads all modules, including Typescript transformer, and that breaks for projects which doesn't use typescript at all? Before these project get typescript installed without notice.
Hi, I can't provide all my code, but it's just a react app with a custom webpack and babel. (not using create-react-app that probably provides typescript under the hood).
Probably just creating a index.jsx file, a minimal webpack configuration, and setup lingui will fail
Here is the crash:
```
12:58:14 > npm run extract && npm run compile
12:58:14
12:58:15
12:58:15 > [email protected] extract /app
12:58:15 > lingui extract
12:58:15
12:58:15 [91minternal/modules/cjs/loader.js:638
12:58:15 throw err;
12:58:15 Error: Cannot find module 'typescript'
12:58:15 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
12:58:15 at Function.Module._load (internal/modules/cjs/loader.js:562:25)
12:58:15 at Module.require (internal/modules/cjs/loader.js:692:17)
12:58:15 at require (internal/modules/cjs/helpers.js:25:18)
12:58:15 at Object.
12:58:15 at Module._compile (internal/modules/cjs/loader.js:778:30)
12:58:15 at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
12:58:15 at Module.load (internal/modules/cjs/loader.js:653:32)
12:58:15 at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
12:58:15 at Function.Module._load (internal/modules/cjs/loader.js:585:3)
12:58:15 [0m[91mnpm ERR![0m[91m code ELIFECYCLE
12:58:15 [0m[91mnpm ERR![0m[91m errno 1
12:58:15 [0m[91mnpm ERR! [email protected] extract: `lingui extract```
What's the reason to put typescript as peer dependecy, when a lot of projects don't need typescript for anything.
That's exactly what peer deps are for, to have list of dependencies that consumers should install.
My guess is that cli loads all modules, including Typescript transformer, and that breaks for projects which doesn't use typescript at all? Before these project get typescript installed without notice.
Yea, that's about right, but since it's a CLI code, we can wrap require('typescript') to try/catch and be happy about it. Webpack won't complain there.
Of course, the ultimate approach would be to have extractors as plugins that are installed separately.
It's more about - you are able to require('typescript') only to parse .tsx(if any found), not __statically__ import it for all cases.
Hello,
any progress on fixing this? Can you update documentation to say that typescript is now required in a minor bump?
Thank you
I am facing the same issue. any progress/update on this ?
It doesn't bother me personally, so either of you is most welcome to work on the PR.
Hi everyone, install typescript globally should fixed this issue.
npm install -g typescript
npm link typescript
then you can now
npm run extract
npm run compile
@jsmirandaiii That's just silly. Yes, it will work, but it's not a scalable solution. Working on the team it means everyone has to do it. And if running builds in CI, it would need to do the same.
I've outlined the proper solution above and it's not that hard (max 5 lines of code) so what about instead of figuring out hacks you try to collaborate and improve something?
馃槑I have an idea how to handle it in 3 lines of code...
Fixed in v2.9.1. 馃帀
Awesome job @theKashey.
Take the inspiration here, you other people who come here asking when it's going to get fixed. Just 5 minutes of thinking, another 5 minutes of coding and done. Definitely less time than trying to figure out a workaround ;) This is open-source software, it won't get better by complaining, but by doing.
Most helpful comment
Hello,
any progress on fixing this? Can you update documentation to say that typescript is now required in a minor bump?
Thank you