Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno support for import assertions? #19850

Closed
uriva opened this issue Jul 15, 2023 · 7 comments
Closed

deno support for import assertions? #19850

uriva opened this issue Jul 15, 2023 · 7 comments

Comments

@uriva
Copy link

uriva commented Jul 15, 2023

the popular webtorrent lib has lines like this:

import json from "./MyJSON.json" assert { type: "json" };

when imported as npm:webtorrent this improt trips deno's compiler and a very cryptic hard to debug error message is output:

error: Uncaught SyntaxError: Unexpected token 'i', "import {cr"... is not valid JSON

is this feature supported in deno? why is the error message not with file and line numbers?

is there some solution to this?

thanks

Related #19834

@petamoriken
Copy link
Contributor

Import Attributes (ex-Import Assertions) are Stage 3 now. We should wait for ECMAScript progress.

related: #17944

@andreubotella
Copy link
Contributor

andreubotella commented Jul 16, 2023

Deno has supported import assertions and JSON modules since 1.17.0. (In fact, recently the import assertions proposal was renamed to import attributes and the assert keyword changed to with, and Deno's existing support of assert means it will have to continue shipping that keyword for at least some time.)

The reason your import is failing seems to be because the JSON file you're importing isn't valid JSON syntax, but seems to be JS or TS.

@uriva
Copy link
Author

uriva commented Jul 16, 2023

@ThaUnknown maybe you'll have an idea?

@ThaUnknown
Copy link

my idea is that webtorrent doesn't support deno, as I've already told you once before

@sigmaSd
Copy link
Contributor

sigmaSd commented Jul 16, 2023

it seems like the node compat doesn't support npm packages that have import assertion

this fails the same way import "npm:@sigmasd/a/a.js"; where a.js only have this

import b from "./b.json" assert { type: "json" };
console.log(b);

@await-ovo
Copy link
Contributor

Is it related to #17942 ?

@uriva uriva closed this as completed May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants