Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Error: Cannot find module '@storybook/experimental-addon-test/internal/coverage-reporter' in monorepo setups #29785

Closed
Tracked by #29531
JReinhold opened this issue Dec 2, 2024 · 1 comment · Fixed by #30026
Assignees
Labels

Comments

@JReinhold
Copy link
Contributor

JReinhold commented Dec 2, 2024

In certain monorepo scenarios, Vitest can fail to resolve @storybook/experimental-addon-test/internal/coverage-reporter if it has been hoisted or similar. We are not in control of this resolution, we simply pass in a string to a custom coverage reporter. See docs at:

https://vitest.dev/guide/coverage.html#custom-coverage-reporter

The problem is here on line 45:

const storybookCoverageReporter: [string, StorybookCoverageReporterOptions] = [
'@storybook/experimental-addon-test/internal/coverage-reporter',
{
testManager: this.testManager,
coverageOptions: this.vitest?.config?.coverage as ResolvedCoverageOptions<'v8'>,
},
];

We could try to use require.resolve (or the ESM equivalent) to get an absolute path at runtime (relative to the current file) instead of referencing the export of our package.

Reproduction

https://github.com/gawdfrey/storybook-experimental-monorepo

  1. npm install
  2. npm run build
  3. npm run dev
  4. Go to localhost:6006 and try to run a test with coverage enabled, you should see error in console.
@ndelangen
Copy link
Member

We can fix this problem, but the underlaying issue of this repro is the multiple versions of storybook being installed.
(multiple CLI versions, multiple core package versions)

This is causing npm to hoist some packages, and not others.
I've looked at what it's doing, and merging @storybook/core and storybook package would actually help, I think. (though I did not try this, so am not sure it would resolve all)

What I was able to do was hack the node_modules a bit to essentially have the require.resolve around the string.

That solves the issue, and I'm able to run the tests.
I'll open a PR.

But it does feel like this monorepo setup is not in a state, that seems long-term supportable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants