D
Deno

help

import plotly.js : invalid or unexpected token ?

Ggeorge1/6/2024
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
DAHDeno AI Helper1/6/2024
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.
Ggeorge1/7/2024
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.
DAHDeno AI Helper1/7/2024
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. 🦕
Ggeorge1/7/2024
That was the exact error message. oo
Rraunioroo1/7/2024
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
Mmarvinh.1/7/2024
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

Looking for more? Join the community!

Recommended Posts
Deno deploy: "Error The deployment failed: ISOLATE_INTERNAL_FAILURE"what's this error? ```js Cloning repository (100%) Project linked successfully. Building first deploModule documentation preview in developmentI am trying to improve development experience when documenting Deno modules. What I would like to acFresh project creation hangingUpgraded deno to 1.39.2 this morning and tried to create a new fresh project. CLI just hangs after eRedirect which deno deploy instance is used?My scenario is that I have one websocket connection on east4 and one on east5 and they need to be abstd/http/setCookie doesn't work?It seems to only support single cookies: ```ts import * as cookies from "https://deno.land/std@0.21Abort signals and node compatibilityDeno and Node's `AbortSignal` types are not compatible. I have verified that I can use a deno Abortdeployctl error: TypeError: request or response body errorHey, I'm getting an error when trying to deploy to a project error: TypeError: request or response bdrizzle orm for deno and sqlite?does drizzle orm work with sqlite and deno?deno queues on deployDoes anyone have a simple example if deno queues + routing that works on demo deploycompile to target, 'unzip' not found.I am on linux ubuntu 22 I downloaded, uninstalled reinstalled, written to path unzip. however no matRecommendations for interacting with Excel sheets (.xlsx) and GraphQL?I want to use Deno in production. Specifically, I'm looking into building a script that reads a `.xlTrouble with Deno importsWhat's wrong with my import? The link is valid and I cached it. (https://deno.land/x/deno_dom@v0.1.How to format on save with devcontainerI'd like to automatically format my code when saving, but it's not working. devcontainer.json ```jsHow does form submission work?I'm following the tutorial: https://fresh.deno.dev/docs/getting-started/form-submissions It says: >