Skip to content

[BUG] Failed to resolve module in math-intrinsics: Fixed by explicit .parcelrc #1331

@DavidNzube101

Description

@DavidNzube101

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

  1. ✅ The file isNaN.js exists in the package directory
  2. ✅ The import statement require('./isNaN') in sign.js is valid
  3. ✅ The package is correctly installed by pnpm
  4. ❌ 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:

  1. Use @parcel/resolver-default by default to ensure compatibility with all package managers, or
  2. 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

  • I would like to fix this BUG via a PR

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.

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