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.

Building Storybook fails, unable to find Jest globals

See original GitHub issue

Describe the bug Running yarn build-storybook fails consistently after upgrading our dependencies. The “Compiling preview” step fails with this output (just a small sample):

ERR! => Failed to build the preview
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(6,1)
ERR!       TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(7,3)
ERR!       TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(9,5)
ERR!       TS2304: Cannot find name 'expect'.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(10,5)
ERR!       TS2304: Cannot find name 'expect'.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(13,3)
ERR!       TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(15,5)
ERR!       TS2304: Cannot find name 'expect'.
ERR! /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx
ERR! [tsl] ERROR in /Users/jackieluo/Development/square-console/packages/sqc-foundation/components/__tests__/Alert.test.tsx(16,5)
ERR!       TS2304: Cannot find name 'expect'.

As one might expect, only test files that use Jest globals are affected. Running the tests and the app, however, works fine—only Storybook is failing.

Expected behavior Storybook builds successfully.

Versions:

  • TypeScript 3.5.2
  • React 16.8.0
  • Storybook 5.1.8
  • Jest 24.8.0
  • @types/jest 24.0.15

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
reaktivocommented, Nov 22, 2019

Hey @jackiehluo, just ran into the same issue as you did (Storybook breaking trying to load test.tsx files). It’s a long shot, but did you find a solution?

0reactions
eranimocommented, Jun 16, 2022

I am literally not even using glob patterns (listing the paths to the stories directly), but storybook is still including all ts files

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Addon | Storybook: Frontend workshop for UI development
React storybook addon that show component jest report. ... You could create a prebuild:storybook npm script, which will never fail by appending ||...
Read more >
Storybook: ReferenceError: jest is not defined - Stack Overflow
Been trying to figure out how to solve the error but I am stuck. EDIT: I resolved the error Jest is not defined...
Read more >
[Sovled] Jest error Cannot find name 'it' in TypeScript
To solve the "Cannot find name 'it'" jest error, make sure to install the typings for jest - npm i -D @types/jest and...
Read more >
jest referenceerror: global is not defined - You.com | The AI ...
Test suite failed to run ReferenceError: global is not defined at Object. ... Describe the bug I am trying to get Vite +...
Read more >
Jest · Delightful JavaScript Testing
By ensuring your tests have unique global state, Jest can reliably run tests in parallel. To make things quick, Jest runs previously failed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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