Add npm packages

A browser project takes its npm packages from package.json. Add one from the NPM PACKAGES list, or import it in your code and install it from the preview. A browser project has no terminal and no npm install.

On this page

Ask the agent

Add the canvas-confetti package to this project.

It adds the package to package.json, and the preview loads it on the next run.

Do it yourself

#
  1. In the file list, find NPM PACKAGES and choose the plus button next to it.
  2. Type the package's name in Search by name, like canvas-confetti, and pick it from the results.
  3. Pick a version. The list shows tags first, like latest, then every version.
  4. The package appears under NPM PACKAGES with its version, and in package.json under dependencies.
  5. Import it in your code, like import confetti from 'canvas-confetti'. The preview loads it on the next run.

You can also start from the import. When your code imports a package that package.json does not have, the preview shows Missing Module with the package and the file that imports it. Pick a version under Select version and choose Install followed by the package's name.

Or edit package.json yourself: the NPM PACKAGES list follows its dependencies.

To remove a package, choose the ... button next to it, then Delete.

If it doesn't work

#

"No packages found"

#

The search found nothing. Check the spelling of the name.

"This package cannot be installed automatically."

#

Playcode could not find the package on npm. Check the name in the import.

The package is installed, but the import fails

#

The package is there, but the path after its name does not resolve, like a file inside the package without its ending. Read the error under the preview: it names the path that failed. Fix the import.

The package does not work in the preview

#

It may need Node.js, like a web server or file access. Code in a browser project runs in your browser. Use a Cloud app for it: see Browser and Cloud projects.

Limits

#
  • Only dependencies count. devDependencies and the scripts in package.json do not run.
  • There is no terminal in a browser project. A Cloud app has one: see Use the terminal.
  • A Python project shows its own packages list instead of NPM PACKAGES.