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.

Self is not defined - Bugsnag/js

See original GitHub issue

Steps to reproduce

  1. I was trying to add bugsnag to my node api and i was following the steps mentioned here https://docs.bugsnag.com/platforms/javascript/
  2. Everything was working normally but suddenly i ran into this error when i started my hapi server with npm start
  3. See error Screenshot 2022-04-20 at 2 40 45 PM

Environment

  • Bugsnag version: 7.16.2

  • Server framework version (if any):

    • Hapi ^16.0.3:
  • Node version : 14.19.1

  • Device : Apple M1 Pro macbook pro

I did not do anything crazy with the setup. I just installed bugsnag -> created a project in bugnsag dashboard -> went on with the steps mentioned in the docs.

Code:

var Bugsnag = require('@bugsnag/js');
 Bugsnag.start({
      apiKey: process.env.BUGSNAG_NOTIFIER_KEY,
      appVersion: require('../package.json').version
    });
Error messages:
ReferenceError · self is not defined

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
luke-beltoncommented, Apr 22, 2022

hi @sayo96 - we’re struggling to see a mechanism by which this would occur, perhaps an IntelliCode plugin or similar autocompleted the require statement in your IDE? I found the original error in your Bugsnag dashboard and it looks like this occurred in a local development environment?

I’m going to close this issue for now as the issue looks to be transient, but if you see this again and are able to provide us with a cut-down reproduction example demonstrating the issue we’d be more than happy to look into this further. Feel free to send this to support@bugsnag.com 👍

1reaction
luke-beltoncommented, Apr 21, 2022

hi @sayo96 - do you require Bugsnag inside your server/controllers/tasks.js file too? It looks like you’re using @bugsnag/browser there which I think is where the issue lies. Could you update this to the following instead to see if that fixes the issue for you?

var Bugsnag = require('@bugsnag/js');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference Error: self is not defined - javascript - Stack Overflow
self is likely referring to window which is not available on the server side...it's only available in a browser context.
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 >
Frequently asked questions - Bugsnag docs
Get help with your Bugsnag JavaScript integration and answers to frequently asked questions.
Read more >
Developers - ReferenceError: self is not defined - - Bountysource
ReferenceError : self is not defined · Expected behavior. Our Webpack Server should start normally · Observed behavior. When running out dev server ......
Read more >
ReferenceError: self is not defined - Blockcerts Forum
Hi all, I am running the server.js sample code for NodeJS and I get the following error: ...
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