Open gplanansky opened 9 months ago
Is this library designed to work in server side runtimes? I get the following in Node.js:
> cat package.json
{
"name": "scratch",
"version": "1.0.0",
"type": "module",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"plotly.js-dist": "^2.28.0"
}
}
> cat main.js
import Plotly from "plotly.js-dist";
console.log(Plotly);
> node main.js
V:\scratch\node_modules\plotly.js-dist\plotly.js:16
})(self, function() {
^
ReferenceError: self is not defined
at Object.<anonymous> (V:\scratch\node_modules\plotly.js-dist\plotly.js:16:4)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
Node.js v18.12.1
Looking at the source of that error above, it seems to be because window
is undefined, which it is in Deno within npm packages (because a window
global existing caused issues (also, see https://github.com/denoland/deno/issues/13367 about possibly removing this from Deno). Also, it seems like a bug that Deno exposes self
here from window.self
Indeed, it is so: https://plotly.com/nodejs/getting-started/ plus there is the matter of network authentication for nodejs mode
@gplanansky so it looks like the plotly
package works in Node (and I'm able to import it in Deno now), but the plotly.js-dist
is the one for the web.
@dsherret what is the import invocation that succeeded for you in Deno? Is it the one to also use with the deno kernel in Jupyter Lab?
@gplanansky I didn't test it further, but based on those node.js instructions this worked for me:
// import Plotly from "npm:plotly.js-dist";
import Plotly from "npm:plotly";
console.log(Plotly);
I confirm that "npm:plotly" does import in Deno.
However, for plotting with the deno kernel in Jupyter Lab, as you all ably do with d3 (https://deno.com/blog/v1.37 ) and Kelly further does with vega-lite (https://blog.jupyter.org/bringing-modern-javascript-to-the-jupyter-notebook-fc998095081e), would take the web plotly.
Unfortunately I guess the plotly.js-dist formulation defeats doing that.
Version: Deno 1.39.2 GIT_COMMIT_HASH=741afc4b94427588c628925fef464623d373430f
MacOS m1
Reproduce Build deno foir aarch64-apple-darwin:
Test deno imports portals ok, fails to import plotly:
$ target/debug/deno Deno 1.39.2 exit using ctrl+d, ctrl+c, or close() REPL is running with all permissions allowed. To specify permissions, run
deno repl
with allow flags.