Skip to content

Unable to import module from across PNPM workspace #762

@gabrielecirulli

Description

@gabrielecirulli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions