"Uncaught ReferenceError: self is not defined" when trying to import using require
See original GitHub issueI get the error in the node repl when trying to import react-plotly using require. In the browser, the call to require('react-plotly.js')
returns undefined, though I don’t any exception in the console.
Welcome to Node.js v16.13.1.
Type ".help" for more information.
> const {Plot} = require('react-plotly.js');
Uncaught ReferenceError: self is not defined
at Object.58 (/home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:9084:9)
at o (/home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:7:631)
at /home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:7:682
at Object.503.../constants/numerical (/home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:128735:10)
at o (/home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:7:631)
at /home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:7:682
at Object.1.../src/lib (/home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:10:11)
at o (/home/sphelps/tmp/test/node_modules/plotly.js/dist/plotly.js:7:631)
I am using the following dependencies:
"dependencies": {
"plotly.js": "^2.8.3",
"react-plotly.js": "^2.5.1"
}
Any suggestions as to what I am doing wrong?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10
Top Results From Across the Web
Typescript + Webpack library generates "ReferenceError: self ...
I believe webpack has set it as self for a certain reason. But in order to work on browser and node you can...
Read more >ReferenceError: self is not defined - Blockcerts Forum
This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it...
Read more >node-self - npm
Start using node-self in your project by running `npm i ... But, in Node.js console.log(self); // ReferenceError: self is not defined.
Read more >NextJS ReferenceError: self is not defined
Hi everyone,. I keep getting error every time I refresh the page that renders the map. I'm using the “@tomtom-international/web-sdk-maps” and “@ ...
Read more >ReferenceError: exports is not defined in TypeScript | bobbyhadz
If you are getting the error for code that runs in the browser, try defining a global exports variable above the script tags...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
how would this work in next.js with typescript I’m getting the same issue but Im using es6 imports.
import Plot from 'react-plotly.js';
spits out the same issue
This resolved it for me, in next.js:
My understanding is that you basically need to skip
react-plotly.js
import/execution during SSR.Additionally, I’m using Typescript in next.js, and referencing the
PlotParams
type; that import seems to still work directly from the package: