storybook: [Bug]: Invariant failed: Expected package.json#version to be defined in the "undefined" package}
Describe the bug
While upgrading my project from storybook 7 to 8, I noticed that serving does not work any more, with the following error:
Error: Invariant failed: Expected package.json#version to be defined in the "undefined" package}
at invariant (/home/jojoxd/Development/<PROJECT>/node_modules/@storybook/core/dist/core-server/index.cjs:187629:11)
at buildDevStandalone (/home/jojoxd/Development/<PROJECT>/node_modules/@storybook/core/dist/core-server/index.cjs:189878:3)
at Object.build (/home/jojoxd/Development/<PROJECT>/node_modules/@storybook/core/dist/core-server/index.cjs:190006:12)
at runInstance (/home/jojoxd/Development/<PROJECT>/node_modules/@nx/storybook/src/executors/storybook/storybook.impl.js:26:18)
at storybookExecutor (/home/jojoxd/Development/<PROJECT>/node_modules/@nx/storybook/src/executors/storybook/storybook.impl.js:12:26)
at storybookExecutor.next (<anonymous>)
at getLastValueFromAsyncIterableIterator (/home/jojoxd/Development/<PROJECT>/node_modules/nx/src/utils/async-iterator.js:15:34)
at iteratorToProcessStatusCode (/home/jojoxd/Development/<PROJECT>/node_modules/nx/src/command-line/run/run.js:44:94)
at /home/jojoxd/Development/<PROJECT>/node_modules/nx/src/command-line/run/run.js:187:16
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
It looks like this change was made incorrectly, as the package.json’s content should be read, instead of fetching the dirname.
Reproduction link
https://example.com/there-is-no-reproduction
Reproduction steps
No response
System
Storybook Environment Info:
System:
OS: Linux 6.8 Ubuntu 24.04 LTS 24.04 LTS (Noble Numbat)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm <----- active
npmPackages:
@storybook/addon-essentials: 8.2.2 => 8.2.2
@storybook/addon-interactions: 8.2.2 => 8.2.2
@storybook/core-server: 8.2.2 => 8.2.2
@storybook/jest: ^0.2.3 => 0.2.3
@storybook/test-runner: ^0.19.1 => 0.19.1
@storybook/testing-library: ^0.2.2 => 0.2.2
@storybook/vue3-vite: 8.2.2 => 8.2.2
Additional context
This NX Issue is related: https://github.com/nrwl/nx/issues/26914
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 16 (5 by maintainers)
+1 facing the same issue when upgrading Storybook in my NX monorepo.
Is there any workaround? Facing this issue after doing nx migration.
Hey guys I opened a PR here let me know if this is working on your machine.
cc: @Coly010
I’m waiting for the solution too 🙏
I am facing this same issue while upgrading my storybook in nx
+1
+1 I have the same error. All dependencies of storybook have the same version.
@bakervos Sorry for the hassle! It seems like we’ve broken the
nxintegration in 8.2. We’re meeting with the nx team later this week to get it resolved. In the meantime, if you upgrade to 8.1 I think you should be OK (though nx support for 8.x isn’t official yet AFAIK).Am using Storybook 8.2.7 and am still facing this issue apparently;
EDIT: just noticed the fix was merged 3 days ago; and the release isnt out yet
@ilhamsa1 and @christopher-drifte if you want to get storybook running in the meantime try removing the storybook target on your
project.jsonfile listed on the libraries you are running storybook for:if your project doesn’t already have it defined, go to the
nx.jsonfile and add storybook as a plugin:@shilman just a note to add, this only happens when serving Storybook (start command),
storybook buildstill works as expected without any issue** Disclaimer** This information might be inaccurate, due to it being generated automatically To resolve the issue, modify the
core-servermodule to correctly read thepackage.jsonversion. Specifically, update theindex.tsandutils/package-json.tsfiles.package.jsonis being read correctly.package.json.About Greptile
This response provides a starting point for your research, not a precise solution.
Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Edit Issue Bot Settings