question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Builder breaks with package managers that don't hoist (e.g. pnpm)

See original GitHub issue

I recently tried to upgrade from version 0.0.8 to 0.0.10 on my repo, which is using pnpm as its package manager.

pnpm does not hoist dependencies (so, for example, storybook’s dependencies are not available in the project’s top level node_modules).

When starting a project with storybook-builder-vite and pnpm, we see this error: Error: Failed to resolve force included dependency: airbnb-js-shims, which is one of the forced optimized dependencies here: https://github.com/eirslett/storybook-builder-vite/blob/main/packages/storybook-builder-vite/optimizeDeps.js

I’m confused because:

  • this used to work in 0.0.8 and airbnb-js-shims was in that list there
  • require.resolve("airbnb-js-shims") shouldn’t work from this file in pnpm, based on my understanding of node module resolution and pnpm. It is resolving, so something is wrong with my understanding

Manually installing airbnb-js-shims fixes this error, but it is replaced with the next one down the list.

Reproduction here: https://github.com/Pinpickle/storybook-builder-vite-0.0.10-pnpm-bug (you can run it under pnpm and yarn to see it breaking and working)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:45
  • Comments:41 (11 by maintainers)

github_iconTop GitHub Comments

33reactions
IanVScommented, Oct 10, 2022

FWIW, we are working on improved pnpm support in 7.0, and our goal is to not require any hoisting or workarounds.

28reactions
Pinpicklecommented, Jul 1, 2021

I found the offending commit: https://github.com/eirslett/storybook-builder-vite/commit/dde6b5fbe56c3fb24ff53c564e61a334984903cc, AKA #28

Basically, as the root used to be inside storybook-builder-vite, the resolutions in optimizeDeps are relative to the root. Now that the root is in the project itself, these resolutions aren’t necessarily correct.

So we want some optimized deps/import to be relative to storybook-builder-vite and the rest be relative to the project root.

Not sure how to accomplish that, though 😅


In the meantime, I’ve added this to my viteFinal to basically undo that commit:

const { dirname } = require("path");

// https://github.com/eirslett/storybook-builder-vite/issues/55
config.root = dirname(require.resolve("storybook-builder-vite"));
config.server.fsServe = undefined;

And it works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Builder breaks with package managers that don't hoist (eg ...
I recently tried to upgrade from version 0.0.8 to 0.0.10 on my repo, which is using pnpm as its package manager. pnpm does...
Read more >
Advanced package manager features for npm, Yarn, and pnpm
The root problem of this flat node_modules layout is a concept called hoisting, which was introduced by npm in v3. This same dependency ......
Read more >
package.json | pnpm
During local development, pnpm will always fail with an error message if its version does not match the one specified in the engines...
Read more >
Choosing a Node.js package manager for your next project
Introduction. In this post, I take a look at the current state of Node.js package managers and how you can choose between them....
Read more >
if you don't want pnpm to fail on peer dependency issues, add ...
When configuring pnpm in a monorepo with workspaces, using hoist=false to guarantee isolation of packages from each other, and with strict peer dependencies ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found