What happened?
When building a Plasmo extension with pnpm, the build fails with a module resolution error for math-intrinsics package, even though the file exists and the import path is valid. The issue is resolved by creating a .parcelrc file that explicitly uses @parcel/resolver-default.
Environment
- Plasmo version: 0.90.5
- Package manager: pnpm v10.18.3
- Project structure: pnpm workspace (monorepo)
- Target browser: Firefox MV2
- Node version: (your version here)
- OS: Arch Linux
The Error
🔴 ERROR | Build failed. To debug, run plasmo dev --verbose.
🔴 ERROR | Failed to resolve './isNaN' from './node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/sign.js'
🔴 ERROR | Error parsing JSON
Dependency Chain
The math-intrinsics package is a transitive dependency:
my-extension
└── ed25519-hd-key
└── create-hmac
└── cipher-base
└── to-buffer
└── typed-array-buffer
└── call-bound
└── get-intrinsic
└── math-intrinsics@1.1.0
What We Verified
- ✅ The file
isNaN.js exists in the package directory
- ✅ The import statement
require('./isNaN') in sign.js is valid
- ✅ The package is correctly installed by pnpm
- ❌ The build still fails with resolution error
Attempted Solutions (That Didn't Work)
- Clearing pnpm cache and reinstalling
- Using pnpm overrides to downgrade
math-intrinsics
- Configuring pnpm hoisting via
.npmrc
- Running
pnpm why to trace the dependency
The Solution
Creating a .parcelrc file in the extension directory:
{
"extends": "@parcel/config-default",
"resolvers": ["@parcel/resolver-default"]
}
This immediately resolved the issue and the build succeeded.
Analysis
This suggests that Plasmo's default Parcel configuration uses a custom resolver that doesn't properly handle CommonJS require() statements in pnpm's symlinked .pnpm directory structure. Explicitly specifying the default resolver fixes the problem.
Expected Behavior
Plasmo should either:
- Use
@parcel/resolver-default by default to ensure compatibility with all package managers, or
- Document this limitation and the workaround in the docs
Additional Context
This issue is not specific to pnpm's node_modules structure. The same project without the custom .parcelrc won't work with either npm & yarn.
Version
Latest
What OS are you seeing the problem on?
Linux
What browsers are you seeing the problem on?
Firefox
Relevant log output
[skipp@archlinux gorbag]$ yarn dev build --target=firefox-mv2
yarn run v1.22.22
warning package.json: No license field
warning ../../../../../package.json: No license field
$ plasmo dev build --target=firefox-mv2
🟣 Plasmo v0.90.5
🔴 The Browser Extension Framework
🔵 INFO | Starting the extension development server...
🔵 INFO | Building for target: firefox-mv2
🔵 INFO | Loaded environment variables from: []
🔴 ERROR | Build failed. To debug, run plasmo dev --verbose.
🔴 ERROR | Failed to resolve './isNaN' from './node\_modules/math-intrinsics/sign.js'
🔴 ERROR | Error parsing JSON
(OPTIONAL) Contribution
Code of Conduct
What happened?
When building a Plasmo extension with pnpm, the build fails with a module resolution error for
math-intrinsicspackage, even though the file exists and the import path is valid. The issue is resolved by creating a.parcelrcfile that explicitly uses@parcel/resolver-default.Environment
The Error
Dependency Chain
The
math-intrinsicspackage is a transitive dependency:What We Verified
isNaN.jsexists in the package directoryrequire('./isNaN')insign.jsis validAttempted Solutions (That Didn't Work)
math-intrinsics.npmrcpnpm whyto trace the dependencyThe Solution
Creating a
.parcelrcfile in the extension directory:{ "extends": "@parcel/config-default", "resolvers": ["@parcel/resolver-default"] }This immediately resolved the issue and the build succeeded.
Analysis
This suggests that Plasmo's default Parcel configuration uses a custom resolver that doesn't properly handle CommonJS
require()statements in pnpm's symlinked.pnpmdirectory structure. Explicitly specifying the default resolver fixes the problem.Expected Behavior
Plasmo should either:
@parcel/resolver-defaultby default to ensure compatibility with all package managers, orAdditional Context
This issue is not specific to pnpm's node_modules structure. The same project without the custom
.parcelrcwon't work with either npm & yarn.Version
Latest
What OS are you seeing the problem on?
Linux
What browsers are you seeing the problem on?
Firefox
Relevant log output
(OPTIONAL) Contribution
Code of Conduct