Errors with pnpm
- Medusa supports
pnpmas of v2.13.0. Refer to the Use pnpm with Medusa guide for instructions on how to set uppnpmin your Medusa project. pnpmcan be used in monorepo setups with proper workspace configuration. Refer to the Using pnpm with Medusa guide for details on how to configurepnpmworkspaces 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:
You may also receive an error related to Tanstack Query:
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:
Then, reinstall your dependencies:
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:
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:
Adjust the patterns to match the directories where your packages are located. Common mistakes include:
- Missing the
packagesfield entirely - Using an empty
packagesarray - Incorrect glob patterns that don't match your project structure
After fixing the file, reinstall dependencies and redeploy: