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.

Jest error: ReferenceError: self is not defined

See original GitHub issue

In the latest version of the library, we get the following error when using jest:

    ReferenceError: self is not defined

      4 | import { findWithType } from 'react-shallow-testutils';
      5 | import ShallowRenderer from 'react-test-renderer/shallow';
    > 6 | import WaveSurfer from 'wavesurfer.js';
        | ^

This was caused by a change removing globalObject: 'this' from the build config in https://github.com/katspaugh/wavesurfer.js/commit/d27b75e29b16e1b0d425eefa83bd0b0e1891f067.

There is a workaround by setting testEnvironment: 'jsdom' in the jest config, but this causes issues for things in the node environment.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:15

github_iconTop GitHub Comments

7reactions
bencehusicommented, Jan 5, 2022

Did not really work.

Anyone who is looking for a Next.js solution, use the dynamic loader to load your component that contains the wavesurfer import:

import dynamic from 'next/dynamic'

const PodcastPlayer = dynamic(
    () => import('@/components/atoms/PodcastPlayer'),
    { ssr: false }
)
2reactions
command-tabcommented, Feb 23, 2022

Same here with Vue/Nuxt

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest fails with 'self is not defined' when importing react-diagrams
Jest fails with 'self is not defined' when importing react-diagrams ; import { DiagramModel } ; ReferenceError: self is not defined > 1...
Read more >
'Server Error: Self is Not Defined' When Used During SSR
When used in an SSR build (NextJS in this case) the following error is thrown: Server Error ReferenceError: self is not defined.
Read more >
Getting "Reference Error: self is not defined" - plotly.js
Hello. I have been trying to use plotly charts in React. I have defined the component given below, and have used it simply...
Read more >
Error 'self is not defined' when using in Jest test - Bountysource
Im trying to create a basic jest test interacting with react-diagrams classes. The failing test.
Read more >
ReferenceError: self is not defined - MongoDB
I'm using mongodb-stitch-browser-sdk 4.8.0. I'm simply trying to import Stitch using this code…
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