1

I need to have a colormap on my javascript page. I am using Flask for server side (written in python). I have a javascript file that requires colormap module (installed using "npm install colormap"), for rendering colormaps on the client side. I tried to import it from my javascript file index.js

var colormap = import("colormap");

which I got the error:

index.js:2 Uncaught (in promise) TypeError: Failed to resolve module specifier 'colormap'
    at index.js:2

and I also tried:

let colormap = require('colormap')

and I got the error require is not defined.

how can I solve it? I am trying to import the js file with colormap directly into my html (so the javascript file will have reference), but I cant find what file should I import.

Kenny Smith
  • 729
  • 3
  • 9
  • 23
  • I want to try and add the – Kenny Smith Jul 26 '20 at 15:30

1 Answers1

2

The NPM package colormap is not set up well for just importing into a client-side JS script.

If it was, you could just include it in a script tag as described here.

Because it is not, you will have to use Browserify to convert the JS into a file that you can then serve and use in your JS.

Luke Storry
  • 6,032
  • 1
  • 9
  • 22