Plasmo Framework CLI
The Plasmo Framework is a comprehensive Software Development Kit (SDK) designed for building browser extensions with a focus on developer experience, akin to Next.js for web applications. It abstracts away complex configuration, offering first-class support for React and TypeScript. Key features include declarative development, Content Scripts UI, Tab Pages, live-reloading with React HMR, environment file support, and built-in Storage and Messaging APIs. The framework simplifies targeting multiple browsers and manifest versions, and supports automated deployment via Browser Publish Protocol (BPP). It is currently in a stable state with version `0.90.5`, maintaining a rapid release cadence with frequent minor updates and patch fixes. Its differentiators lie in its 'batteries-included' approach, robust tooling, and focus on streamlining the extension development workflow.
Common errors
-
Error: ENOENT: no such file or directory, stat '<path>'
cause A file system operation, often involving internal asset handling, failed because a required file or directory was not found.fixUpgrade Plasmo to `v0.90.5` or later, which includes improved error handling for ENOENT. Ensure all files referenced in your project exist at the correct paths. -
TypeError: `defineManifest` must return an object (Got type string)
cause The `manifest.ts` file is not correctly exporting a manifest object. This typically occurs if `defineManifest` is not used or if its return value is not a plain object.fixEnsure your `manifest.ts` explicitly uses `export default defineManifest({ ... })` and that the object passed to `defineManifest` is well-formed. -
Refused to create a Trusted Type policy because the name 'plasmo' is not a valid policy name. (Browser Console Error)
cause A Content Security Policy (CSP) restriction is preventing Plasmo's internal loading indicator from creating a necessary TrustedTypePolicy in the browser environment.fixUpgrade Plasmo to `v0.90.1` or later, as this version includes specific bug fixes to address TrustedTypePolicy CSP compatibility issues. Review your extension's CSP if the issue persists on older Plasmo versions.
Warnings
- breaking Plasmo versions prior to `v0.90.1` may not fully support React 19. Using newer React versions with older Plasmo releases could lead to build or runtime inconsistencies.
- gotcha Content Security Policy (CSP) restrictions and `TrustedTypePolicy` creation could cause runtime errors, particularly affecting loading indicators in browser extensions built with Plasmo versions before `v0.90.1`.
- gotcha In Plasmo versions before `v0.89.3`, the framework's internal new version check mechanism could inadvertently block or significantly delay `plasmo dev` and `plasmo build` commands, hindering the development workflow.
- gotcha Updates to native dependencies like `sharp` (e.g., in `v0.90.2`) can sometimes introduce platform-specific build failures. If you encounter build issues after a Plasmo update, especially on different operating systems, native module conflicts might be the cause.
Install
-
npm install plasmo -
yarn add plasmo -
pnpm add plasmo
Imports
- defineManifest
import { defineManifest } from 'plasmo' - PlasmoCSUI
import type { PlasmoCSUI } from 'plasmo' - PlasmoExtensionManifest
import type { PlasmoExtensionManifest } from 'plasmo'
Quickstart
npx plasmo init my-extension cd my-extension pnpm install # Or npm install / yarn install # Start development server with live-reloading plasmo dev # Build for production, e.g., for Chrome, Manifest V3, and create a zip file plasmo build --target=chrome-mv3 --zip