Plotly.js: Node package causes errors

Created on 17 Apr 2016  路  3Comments  路  Source: plotly/plotly.js

Calling plotly like this:

var Plotly = require('plotly.js');

Causes this:

/Users/bryan/tibra/web3/node_modules/plotly.js/src/lib/index.js:416
        var style = document.createElement('style');
                    ^
ReferenceError: document is not defined
    at Object.lib.addStyleRule (/Users/bryan/tibra/web3/node_modules/plotly.js/src/lib/index.js:416:21)
    at Object.<anonymous> (/Users/bryan/tibra/web3/node_modules/plotly.js/build/plotcss.js:61:16)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/bryan/tibra/web3/node_modules/plotly.js/src/plotly.js:30:1)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/bryan/tibra/web3/node_modules/plotly.js/src/core.js:15:14)

Most helpful comment

What about web frameworks that use SSR (server-side rendering)?

We use Next.js, which server-renders first, and it is a bug for us as well.

All 3 comments

plotly.js is browser package, with no intention of working in vanilla node.js.

In order to do so, you'll need use jsdom (or a similar package).

Here's my preliminary attempt: https://gist.github.com/etpinard/bee7d62b43b6bb286950

I ran into a few issues, and it is not in a working state. But, we hope to solve these issue shortly to offer server-side plotly.js rendering.

What about web frameworks that use SSR (server-side rendering)?

We use Next.js, which server-renders first, and it is a bug for us as well.

and it is a bug for us as well.

Even when using jsdom?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taybart picture taybart  路  4Comments

jonmmease picture jonmmease  路  3Comments

nicolaskruchten picture nicolaskruchten  路  3Comments

hashimmoosavi picture hashimmoosavi  路  3Comments

emanuelsetitinger picture emanuelsetitinger  路  3Comments