test-runner icon indicating copy to clipboard operation
test-runner copied to clipboard

[Bug] Missing dependency requirement

Open DamienCassou opened this issue 2 years ago • 5 comments

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:

  • /project/node_modules/@storybook/core-common/node_modules/@babel/preset-typescript
  • /project/node_modules/jscodeshift/node_modules/@babel/preset-typescript

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

  • OS: Fedora 36
  • Node.js version: 16.15.0
  • NPM version: 8.5.5
  • Yarn version: 1.22.18

DamienCassou avatar Jul 21 '22 11:07 DamienCassou

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.

emilbjorklund avatar Aug 19 '22 13:08 emilbjorklund

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!

hey-robin avatar Aug 31 '22 17:08 hey-robin

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?

fabis94 avatar Oct 27 '22 18:10 fabis94

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

bobohuochai avatar Dec 09 '22 09:12 bobohuochai

The same issue. Workaround in this topic helped

AlekseyMalakhov avatar May 17 '23 09:05 AlekseyMalakhov