george
george•7mo ago

import plotly.js : invalid or unexpected token ?

import Plotly from "npm:plotly.js-dist"; yields Stack trace: SyntaxError: Invalid or unexpected token at file:///Users/george/Library/Caches/deno/npm/registry.npmjs.org/plotly.js-dist/2.28.0/plotly.js:1091:14 $ cat plotly.js-dist/2.28.0/package.json
{
"name": "plotly.js-dist",
"version": "2.28.0",
"description": "Ready-to-use plotly.js distributed bundle.",
"license": "MIT",
"main": "plotly.js",
"repository": {
"type": "git",
"url": "https://github.com/plotly/plotly.js.git"
},
"bugs": {
"url": "https://github.com/plotly/plotly.js/issues"
},
"author": "Plotly, Inc.",
"keywords": [
"graphing",
"plotting",
"data",
"visualization",
"plotly"
],
"files": [
"LICENSE",
"README.md",
"plotly.js"
]
}
{
"name": "plotly.js-dist",
"version": "2.28.0",
"description": "Ready-to-use plotly.js distributed bundle.",
"license": "MIT",
"main": "plotly.js",
"repository": {
"type": "git",
"url": "https://github.com/plotly/plotly.js.git"
},
"bugs": {
"url": "https://github.com/plotly/plotly.js/issues"
},
"author": "Plotly, Inc.",
"keywords": [
"graphing",
"plotting",
"data",
"visualization",
"plotly"
],
"files": [
"LICENSE",
"README.md",
"plotly.js"
]
}
importing d3 and nodjs-polars works ok. macos deno --version deno 1.39.1 (release, aarch64-apple-darwin) v8 12.0.267.8 typescript 5.3.3
6 Replies
Deno AI Helper
Deno AI Helper•7mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the error message you've provided, it seems like there might be an issue with the file plotly.js at line 1091, character 14. This could be due to an unexpected character or syntax error within the Plotly.js file itself. Since the error is pointing to the Plotly.js file, it's possible that the file might contain code that is not compatible with Deno or there might be an encoding issue. This advice is not based on the Deno documentation, so please double-check the accuracy of this advice. If you are confident that the syntax of your import statement is correct and that you are importing the correct module, you might want to check the contents of the plotly.js file around the mentioned line to see if there's an obvious issue. If the file is minified or otherwise obfuscated, it might be difficult to debug directly. Remember that Deno has a different module resolution system compared to Node.js, and it's possible that some npm packages might not work out of the box with Deno, especially if they rely on Node.js-specific APIs or features. If you continue to have issues, you might want to consider reaching out to the maintainers of the plotly.js-dist package or searching for any known compatibility issues between this package and Deno.
george
george•7mo ago
The files plotly.js and package.json are ok, no diff wrt the same being imported successfully in other ways. So yes, it's a deno idiosyncracy.
Deno AI Helper
Deno AI Helper•7mo ago
It seems like you're having an issue with importing a package in Deno. Deno handles imports differently than Node.js. In Deno, you need to provide the full path to the module you're importing, including the file extension. This is different from Node.js, where you can omit the file extension and Node.js will try to resolve it for you. If you're trying to import a package from npm, you might run into issues because Deno doesn't support the Node.js module resolution algorithm. However, Deno does provide built-in compatibility with Node.js modules through the node: prefix. For example, you can import the fs module from Node.js in Deno like this: import { readFileSync } from "node:fs";. If you're trying to use a package that's not a built-in Node.js module, you can use a CDN like esm.sh or Skypack. These CDNs provide ES module versions of npm packages, which you can import directly in Deno. For example, you can import the lodash package like this: import lodash from "https://esm.sh/lodash";. If you're using a package.json file to manage your dependencies, Deno can use this file to resolve dependencies. However, this feature is limited to instances where code uses a bare specifier that matches an entry in the package.json file. If you're still having issues, could you provide more details about the problem? For example, what is the exact error message you're seeing? What code are you trying to run? The more information you provide, the better I can help you. 🦕
george
george•7mo ago
That was the exact error message. oo
raunioroo
raunioroo•7mo ago
Pretty weird that it gives the same syntax error every time, but for a different line number each time. Line number appears to be pretty random, and there are no obvious syntax errors on those lines when looking at the cached plotly.js file:
> deno repl
Deno 1.39.2
exit using ctrl+d, ctrl+c, or close()
> import Plotly from "npm:plotly.js-dist@2.27.1"
Uncaught SyntaxError: Invalid or unexpected token at file:///home/xxx/.cache/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:193:14
at async <anonymous>:1:52
> deno repl
Deno 1.39.2
exit using ctrl+d, ctrl+c, or close()
> import Plotly from "npm:plotly.js-dist@2.27.1"
Uncaught SyntaxError: Invalid or unexpected token at file:///home/xxx/.cache/deno/npm/registry.npmjs.org/plotly.js-dist/2.27.1/plotly.js:193:14
at async <anonymous>:1:52
marvinh.
marvinh.•7mo ago
This sounds like a bug in the swc, the JS parser that Deno uses. I've filed an issue on GitHub for this https://github.com/denoland/deno/issues/21836