storybookjs / test-runner

🚕 Turn stories into executable tests
https://storybook.js.org/docs/writing-tests/interaction-testing
MIT License
233 stars 72 forks source link

[Bug] Missing dependency requirement #152

Open DamienCassou opened 2 years ago

DamienCassou commented 2 years ago

Describe the bug

$ npx run test-storybook
  ● Test suite failed to run

    Cannot find module '@babel/preset-typescript'
    Require stack:
    - /project/node_modules/@babel/core/lib/config/files/plugins.js
    - /project/node_modules/@babel/core/lib/config/files/index.js
    - /project/node_modules/@babel/core/lib/index.js
    - /project/node_modules/@storybook/test-runner/playwright/transform.js
    - /project/node_modules/jest-util/build/requireOrImportModule.js
    - /project/node_modules/jest-util/build/index.js
    - /project/node_modules/jest-resolve/build/resolver.js
    - /project/node_modules/jest-resolve/build/index.js
    - /project/node_modules/jest-runtime/build/index.js
    - /project/node_modules/jest-runner/build/testWorker.js
    - /project/node_modules/jest-worker/build/workers/processChild.js

It seems that @babel/core and babel presets referenced from playwright/transform.js should be added to dependencies or peerDependencies in your package.json.

This is not a problem for most people because babel dependencies will be available at the root of node_modules/ anyway but it becomes a problem when the package manager (yarn in my case) decides to move babel packages to where they are used instead of the top-level:

Workaround

As a workaround, users facing this issue can declare these dependencies in their own package.json:

{
  "devDependencies": {
    "@babel/core": "^7.18.9",
    "@babel/preset-env": "^7.18.9",
    "@babel/preset-react": "^7.18.6",
    "@babel/preset-typescript": "^7.18.6"
  }
}

Environment

emilbjorklund commented 2 years ago

Also being bitten by this, using yarn. Took me ages to figure out where the issue originated and finding this issue. Seems like a definite bug.

hey-robin commented 2 years ago

Also experiencing this issue using yarn :/ Yarn version: 1.22.19 Node version 14.20.0

Adding @babel/preset-typescript as a devDependency did the trick. Thanks for the workaround!

fabis94 commented 2 years ago

Running into the same issue. Is it possible to make it at least not bundle the React dependency, as I'm running this in a Vue project?

bobohuochai commented 1 year ago

Running into the same issue. Is it possible to make it at least not bundle the React dependency, as I'm running this in a Vue project?

+1

AlekseyMalakhov commented 1 year ago

The same issue. Workaround in this topic helped