ivanhofer / typesafe-i18n

A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.
https://github.com/ivanhofer/typesafe-i18n
MIT License
2.26k stars 78 forks source link

Unable to import module from across PNPM workspace #762

Open gabrielecirulli opened 7 months ago

gabrielecirulli commented 7 months ago

Version

5.26.2

Describe the bug

I have a PNPM workspaces repository with the following structure

apps/
  - frontend/
logic/
  - core/

I've set up typesafe-i18n in my frontend package. From this package, I can usually import stuff in core using @my-repo/core.

However, the typesafe-i18n watcher does not seem able to work with this setup. Within my en/index.ts file I'm importing an enum from core in order to populate a set of translations corresponding to each enum entry. Here's an example:

import { MyEnum } from "@my-repo/core";
import type { BaseTranslation } from "../i18n-types";

const en = {
  stuff: {
    [MyEnum.First]: {
      title: "First thing",
    },
    [MyEnum.Second]: {
      title: "Second thing",
    },
    // etc.
  },
} satisfies BaseTranslation;

export default en;

Here's the error I get:

[typesafe-i18n] ERROR: import failed for /Users/user/my-repo/apps/frontend/node_modules/typesafe-i18n/temp-output/1/en/index.js Error: Cannot find module '@my-repo/core'
Require stack:
- /Users/user/my-repo/node_modules/.pnpm/typesafe-i18n@5.26.2_typescript@5.4.2/node_modules/typesafe-i18n/temp-output/1/en/index.js
[typesafe-i18n] ERROR: could not read default export from base locale file 'en'

Reproduction

  1. Set up a PNPM monorepo with the following structure

pnpm-workspaces.yaml:

packages:
  - "apps/frontend"
  - "logic/core"
  1. Set up typesafe-i18n in apps/frontend
  2. Export an enum from somewhere in logic/core

Logs

No response

Config

No response

Additional information

No response

PaHell commented 3 months ago

Same issue here, moving back the client to frontend.

dmitryzhorovPb commented 3 weeks ago

Same issue with turborepo. But error msg for me looks like: [typesafe-i18n] ERROR: import failed for .....node_modules/typesafe-i18n/temp-output/specs/0/de/index.js SyntaxError: Unexpected token 'export' [typesafe-i18n] ERROR: could not read default export from base locale file 'de'