0

I am trying to runt the following code on using node:

const require = require("requirejs");

require.config({
    paths: {
        d3: 'https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.min',
        plotly: 'https://cdn.plot.ly/plotly-latest.min',
        jquery: 'https://code.jquery.com/jquery-3.3.1.min'
    },

    shim: {
        plotly: {
            deps: ['d3', 'jquery'],
            exports: 'plotly'
        }
    }
});


require(['plotly'], function(Plotly) {
    window.Plotly = Plotly;
})

Inspiration for this comes from here: Link

Now when I run:

node main.js

I get the following error:

throw err;

Error: Tried loading "plotly" at https://cdn.plot.ly/plotly-latest.min.js then tried node's require("plotly") and it failed with error: Error: Cannot find module 'plotly'

Could someone please kindly explain what is going on and how I can fix this error message?

3
  • 2
    requirejs.org/docs/node.html#2: "RequireJS in Node can only load modules that are on the local disk -- fetching modules across http, for instance, is not supported at this time." Commented Jun 24, 2020 at 17:30
  • Although I'm not sure what you're trying to do and why? Node doesn't have a window object so even if you manage to load the libraries then window.Plotly would just fail. Also unclear why you're using RequireJS and what you're planning to do with jQuery. Commented Jun 24, 2020 at 17:33
  • Thanks @GuyIncognito, I was meant to take out the window.plotly thing. Essentially I will be running this stuff inside a jsdom instance. I was trying to load these external libraries for unit testing purposes. I think your first comment clears this issue up for me thanks! Commented Jun 24, 2020 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.