Skip to content

fix: Build fails with Lingui/Vite error when using yarn instead of npm#4571

Open
harshit078 wants to merge 16 commits into
vendurehq:masterfrom
harshit078:fix-lingui-yarn-error
Open

fix: Build fails with Lingui/Vite error when using yarn instead of npm#4571
harshit078 wants to merge 16 commits into
vendurehq:masterfrom
harshit078:fix-lingui-yarn-error

Conversation

@harshit078
Copy link
Copy Markdown
Contributor

@harshit078 harshit078 commented Mar 26, 2026

Description

  • this PR addresses issue Build fails with Lingui/Vite error when using yarn instead of npm #4365
  • added createRequire to resolve the absolute paths to @babel/preset-typescript, @babel/preset-react, and @lingui/babel-plugin-lingui-macro from the dashboard location.
  • By passing absolute paths, we bypass Babel's resolution logic entirely. This works no matter if we use yarn or npm

Breaking changes

No

Screenshots

You can add screenshots here if applicable.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vendure-storybook Ready Ready Preview, Comment Jun 3, 2026 10:23am

Request Review

@vendure-ci-automation-bot
Copy link
Copy Markdown
Contributor

vendure-ci-automation-bot Bot commented Mar 26, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df4c386e-7a06-4417-a68b-d2fd7a0dc6bb

📥 Commits

Reviewing files that changed from the base of the PR and between 0f758a3 and 8b0afbc.

📒 Files selected for processing (1)
  • packages/dashboard/vite/vite-plugin-lingui-babel.ts

📝 Walkthrough

Walkthrough

The change modifies the Lingui Babel plugin in the Vite configuration to resolve Babel preset and plugin module paths at initialization time rather than relying on string specifiers during transformation. Using createRequire and require.resolve, the plugin now stores concrete paths to @babel/preset-typescript, @babel/preset-react, and the Lingui macro plugin, then passes these resolved paths to babel.transformAsync instead of the original string identifiers.

Possibly related issues

  • The issue addressing Lingui macro module-resolution failures in yarn vs npm Vite builds is directly resolved by this change, which ensures consistent module path resolution regardless of the package manager used.

Possibly related PRs

  • PR introducing the original Babel-based Lingui plugin implementation in the same file shares a direct code-level connection, as this change enhances the module resolution behavior of that same plugin.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: resolving a Lingui/Vite build error that occurs when using yarn instead of npm.
Description check ✅ Passed The description includes the key sections (Description, Breaking changes) with relevant details about the fix and references issue #4365, though test cases remain unchecked.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@harshit078
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

vendure-ci-automation-bot Bot added a commit that referenced this pull request Mar 26, 2026
Copy link
Copy Markdown
Collaborator

@grolmus grolmus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several issues with this PR:

  1. Duplicate importimport { createRequire } from 'node:module' appears twice (lines 1 and 3)
  2. Duplicate createRequire call — both _require and existing require are created from createRequire(import.meta.url), only one is needed
  3. Duplicate presets — the babel config now has BOTH the new resolved presets AND the old require.resolve() ones:
    • presetTypescript + require.resolve('@babel/preset-typescript') → typescript preset runs twice
    • presetReact appears twice in the new code
  4. Incomplete@lingui/babel-plugin-lingui-macro is still using the old require.resolve() approach

The intent is correct (resolve absolute paths for yarn PnP compatibility), but the implementation needs cleanup: remove the duplicate import, remove the duplicate _require/require, replace the old preset entries instead of adding alongside them, and also resolve the lingui plugin.

@michaelbromley
Copy link
Copy Markdown
Member

Hi @harshit078
I’ve looked at this PR and I can’t understand how it works to fix the reported yarn issue. Can you please explain what’s going on and how the changes address the issue?

@harshit078
Copy link
Copy Markdown
Contributor Author

Hey @michaelbromley , sure I'll give a brief detailed answer.

Original issue

  • Build failed with Lingui/Vite error when using yarn instead of npm. When using yarn as the package manager, building the project fails with a Lingui/Vite compilation error. The build process works correctly when using npm instead of yarn.
  • basically on research I found out that @vendure/ui-devkit depends on @angular-devkit/build-angular and @angular/compiler-cli, which depends on @babel/core to 7.26.10 and 7.26.9 respectively. Whereas @vendure/dashboard requires us to have @babel/core@^7.26.0, which resolves to 7.29.0.

Why Npm solved it but not yarn

  • npm simply hoists one copy and then rest of the tree still finds Babel where it should expect it to be.

  • yarn on the end hand can only put one version at the top level. Since 7.26.10 wins, the dashboard's entire @babel/* subtree gets nested under node_modules/@vendure/.

  • What I understood so fat is that babel resolves plugin string names using Node module resolution relative to the file being transformed. With yarn, those packages don't exist on the path from the project root so babel never loads @lingui/babel-plugin-lingui-macro, the macro stays in the source, and Vite's thows the error we see.

Fix

  • In packages/dashboard/vite/vite-plugin-lingui-babel.ts, we resolve three Babel packages once from line 6-10. We then pass these in line 137-138. When babel receives an absolute path instead of a package name, it just simply skips its own logic entirely and loads the file directly.

Why this works for both npm and yarn

  • For npm the @babel/* lives at the top level root and require.resolve from the dashboard finds it way normally without any logic.
  • For yarn the @babel/* is nested under the dashboard and require.resolve from the dashboard this time finds it immediately in its local node_modules.

@harshit078
Copy link
Copy Markdown
Contributor Author

Hey @grolmus , I have pushed a fix for comments you mentioned. Can you please take a look again ? Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants