opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
23 stars 0 forks source link

Problem with importing using package.json's `imports` field. #87

Closed MAST1999 closed 1 month ago

MAST1999 commented 2 months ago

This could be a bug in TypeScript, but since I wasn't sure, I thought I'd ask here first.

It's easy to reproduce, just define a few imports in package.json for example like this:

{
    "imports": {
        "#i18/*": "./src/paraglide/*"
    }
}

And then import it with import * as m from "#i18/message.js", it shows this error:

Could not find a declaration file for module '#i18/messages.js'. 'stackblitz:/src/paraglide/messages.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/vite-react-typescript-starter` if it exists or add a new declaration (.d.ts) file containing `declare module '#i18/messages.js';`

But if I import directly like this import * as m from "./src/paraglide/message" it works. I've followed the setup guides and set the allowJS to true in ts config.

Here's the reproduction: https://stackblitz.com/edit/vitejs-vite-q2fxtt?file=src%2FApp.tsx&terminal=dev

MAST1999 commented 2 months ago

As a workaround, I've added the alias to the ts config as well.

But it would be great if that was not needed.

samuelstroschein commented 2 months ago

@mast1999 you always need to define how typescript should resolve "custom" paths.

I've followed the setup guides and set the allowJS to true in ts config.

can you link the guide? it seems like we can improve the wording

LorisSigrist commented 1 month ago

Closing this as stale