npm, yarn and pnpm are now supported natively in WebContainers

The road to innovation is a long and winding one and includes constant improvements and reiterations. This is very much the story of WebContainers as well. Our team reimagined and redesigned its building blocks multiple times to ensure their utmost speed and safety.

In this spirit, we have been working tirelessly the past year on shipping native support for all major package managers: npm, yarn v1, and pnpm. Last year at ViteConf we revealed that we had landed native support for pnpm and yarn in WebContainers.

Today we’re excited to announce the final piece of the puzzle: we have shipped native support for npm in WebContainers! Available now in all WebContainer projects on StackBlitz, and you can try it out here 🎉

This is a big deal for a few reasons:

Seamless compatibility

The best developer experience is one that “just works”.

Running native package managers wholesale in WebContainers brings seamless compatibility to your workflows, as all of the npm, yarn, and pnpm commands you use on local now run the exact same way inside StackBlitz.

Up to 5x faster than local (!)

It wouldn’t be a StackBlitz release if we didn’t make something a heck of a lot faster, and we’re proud to say this release is no exception.

We’ve been able to achieve up to 5x faster installs for npm, yarn and pnpm in WebContainers than on local. This performance jump is the result of multiple years of R&D into accelerated dependency resolution and rapid disk linking that allows us to run these package managers faster than they can locally. On average, running these package managers on our benchmarks yield between 100-200% on performance speeds compared to local and in some scenarios perform up to 500% faster.

Transitioning from Turbo

Custom solutions always comes with a number of tradeoffs, with the main being the time cost involved in ongoing maintainance. Turbo, our custom npm client, served us well when WebContainers were in their infancy but now that they are a stable technology, native support for package managers is a must to ensure their speed.

With native npm support, we are deprecating Turbo - it will be completely removed on January 1st, 2024. Native npm support means that now you can use all the familiar functionality from npm, such as git dependencies, tarball dependencies, and so on. It is a massive win for compatibility!

Breaking changes

In practical terms, there is a breaking change in peer dependencies affecting the projects hosted on StackBlitz: npm now automatically installs peer dependencies whereas Turbo didn’t to that. This means that if you run into issues, you can remove the lock file and re-run npm install --legacy-peer-deps. Important to note, --legacy-peer-deps will ignore all peer dependencies when installing, in the style of npm version 6 and lower.

When the installation fails, WebContainers will try to re-run the installation if dependencies are automatically installed on boot unless specified otherwise in the .stackblitzrc file.

More to come

With WebContainers being a stable technology, we are now prioritizing the features that will make it even easier to build next-generation apps that can run entirely in the browser. We have a few announcements lined up in the next few weeks so stay tuned by following us on Twitter!

Eric Simons
CEO at StackBlitz making web development fast & secure. Viva la Web!
Explore more from StackBlitz

Subscribe to StackBlitz Updates

A newsletter from StackBlitz covering engineering achievements, product features, and updates from the community.

Using StackBlitz at work?

Create in-browser preview apps for every issue or pull request, share private templates with your org, manage your design system with zero overhead, and more.

Try StackBlitz Teams