plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Webpack v5 compatibility issue (with workaround)

Open kostyfisik opened this issue 4 years ago • 9 comments

With Webpack v5 I failed to run plotly.js, it requires additional stream and assert libs. The complete problem description is available here https://github.com/quasarframework/quasar/issues/11229

As I was pointed Webpack v5 removed the Nodejs polyfills for the web client builds. It seems that plotly.js for the web client rely on Nodejs API , and I get errors saying that some packages are missing. These probably need to be addressed by the plotly.js communty.

For users, if you just want to run your app/website (with a bit of risk), then you can manually install node-polyfill-webpack-plugin which solves the problem.

kostyfisik avatar Nov 09 '21 12:11 kostyfisik

Has there been any movement on this? This impacts multiple CRA apps of mine. I'd like to not have to eject and polyfill. I'd also like to keep using plotly.js in these apps as the package is awesome.

mtgraves avatar Dec 17 '21 02:12 mtgraves

Crazy that this issue is not affecting many more users and driving more attention. image

jmacura avatar Apr 07 '22 21:04 jmacura

Same issue. Need HELP, too.

ZodiacWind avatar Apr 14 '22 13:04 ZodiacWind

@jmacura @ZodiacWind

...if it helps, for my react apps I ended up getting things to work by switching from importing like this:

import Plotly from "plotly.js";
import createPlotlyComponent from 'react-plotly.js/factory';

const Plot = createPlotlyComponent(Plotly);

to simply...

import Plot from 'react-plotly.js';

and I also (maybe related...maybe not but including for completeness) switched from the full plotly to a minified version. So my package.json went from:

"dependencies": {
    ...
    "plotly.js": "^1.58.4",
    "react-plotly.js": "^2.5.1",
    "react-scripts": "^4.0.3",
    ...
  },

to...

"dependencies": {
    ...
    "plotly.js-basic-dist-min": "^2.8.3",
    "react-plotly.js": "^2.5.1",
    "react-scripts": "5.0.0",
    ...
  },

Hope that helps?

mtgraves avatar Apr 14 '22 14:04 mtgraves

@mtgraves Thanks for the tip, but mine is not a react-app, so it is not a relevant workaround.

In my case, I have had to switch from "plotly.js" and "@types/plotly.js" to "plotly.js-dist-min" and "@types/plotly.js-dist-min"

jmacura avatar Apr 14 '22 14:04 jmacura

@mtgraves Thanks. I will have a try.

In my case, I have had to switch from "plotly.js" and "@types/plotly.js" to "plotly.js-dist-min" and "@types/plotly.js-dist-min"

@jmacura What's the difference betwenn "plotly.js" and "plotly.js-dist-min"? Thank you.

ZodiacWind avatar Apr 16 '22 01:04 ZodiacWind

@ZodiacWind as the npm documentation says, plotly.js-dist-min is the "Ready-to-use minified plotly.js distributed bundle." So functionally, there should be no difference.

jmacura avatar Apr 16 '22 05:04 jmacura

@jmacura That's great. Thanks for the information.

ZodiacWind avatar Apr 16 '22 14:04 ZodiacWind

@mtgraves Thanks for the tip, but mine is not a react-app, so it is not a relevant workaround.

In my case, I have had to switch from "plotly.js" and "@types/plotly.js" to "plotly.js-dist-min" and "@types/plotly.js-dist-min"

Worked for me as well, so thanks a lot for saving me a headache!

I was actually afraid to use any type definitions other than @types/plotly.js since they are all listed as long-outdated (months). However, they actually just re-import the type definitions for @types/plotly.js it looks like, so it's fine!

NuclearPhoenixx avatar Feb 21 '24 17:02 NuclearPhoenixx