Errors with pnpm

Note: 
  • Medusa supports pnpm as of v2.13.0. Refer to the Use pnpm with Medusa guide for instructions on how to set up pnpm in your Medusa project.
  • pnpm can be used in monorepo setups with proper workspace configuration. Refer to the Using pnpm with Medusa guide for details on how to configure pnpm workspaces for your Medusa monorepo.

If you use pnpm as a package manager in your Medusa application, you might face errors about missing packages. For example:

Terminal
❯can't resolve @medusajs/dashboard

You may also receive an error related to Tanstack Query:

Terminal
❯No QueryClient set, use QueryClientProvider to set one

Why This Error Occurred#

These errors occur because pnpm uses a strict, isolated node_modules structure. Without the correct hoisting configuration, some packages that Medusa requires in the top-level node_modules directory are not available.

For Tanstack Query, the error occurs because the package is required by @medusajs/dashboard, but pnpm does not automatically hoist it to the top-level node_modules.


How to Fix it#

Add a .npmrc file at the root of your project with the following content:

.npmrc
1public-hoist-pattern[]=*@medusajs/*2public-hoist-pattern[]=@tanstack/react-query3public-hoist-pattern[]=react-i18next4public-hoist-pattern[]=react-router-dom

Then, reinstall your dependencies:

Terminal
❯pnpm install

Refer to the Use pnpm with Medusa guide for full setup instructions.


"packages field missing or empty" Error in Monorepo#

If you get the following error when deploying a monorepo with pnpm workspaces:

Terminal
❯ERROR packages field missing or empty

Why This Error Occurred#

This error occurs when your pnpm-workspace.yaml file is missing or has a malformed packages field. The pnpm-workspace.yaml file defines which directories contain packages in your monorepo.

How to Fix it#

Make sure your pnpm-workspace.yaml file exists at the root of your monorepo and has a valid packages field. For example, if your packages are under an apps directory:

pnpm-workspace.yaml
1packages:2  - "apps/*"

Adjust the patterns to match the directories where your packages are located. Common mistakes include:

  • Missing the packages field entirely
  • Using an empty packages array
  • Incorrect glob patterns that don't match your project structure

After fixing the file, reinstall dependencies and redeploy:

Terminal
❯pnpm install
Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵