D
Deno

help

Is there any way to get Deno to not statically analyze import()?

Ttmcw9/12/2023
I understand that statically analyzing and fetching dynamic import() calls is a good thing for performance, but it's making my usecase impossible - I want to import user code, which may crash, and to handle the error if it, say, throws an error on import. I can do this with browser import(). I can do it with Node. I can't do it with Deno: you basically can't use import statements like you'd expect to if you read the MDN page, which seems like a major move away from this being web-standardsy and also makes dynamic import way less useful. Is there a way to actually dynamically load code, at runtime, that I'm missing?
DAHDeno AI Helper9/12/2023
Based on the documentation, Deno does statically analyze dynamic imports when you're using the deno compile command. This means that if your dynamic import statements are statically analyzable (if you used string literals inside import()), the specifiers will be automatically included in the produced binaries. However, the documentation also mentions that non-statically analyzable dynamic imports won't be included by default. For example, if the import specifier is determined at runtime, Deno won't be able to include it in the compiled binary. To include non-statically analyzable dynamic imports, you can specify an --include <path> flag when running deno compile. This will ensure that the specified module is included in the compiled binary, even if it's not statically analyzable. As for handling errors during the import process, the documentation doesn't provide a clear answer. However, you might be able to use a try-catch block to handle any errors that occur when importing a module. If the imported module throws an error on import, the catch block should be able to handle it. Please note that this information is based on the documentation's opinion and your actual experience may vary. If you're having trouble with this, I would recommend asking for help in the Deno community or filing an issue on the Deno GitHub repository. 🦕
Bbartlomieju9/13/2023
Could you elaborate on what is not working? Besides fetching the code Deno doesn't execute it until you actually call import() If you really need to stop it eagerly fetching the source file something like import("" + "...") should do the job I would appreciate a bug report for this
Ttmcw9/13/2023
there's a bug report i've commented on at https://github.com/denoland/deno/issues/18557 - if you have a dynamic import that points to a module that has a git+ dependency, your import() method is permanently broken
GitHub
Support npm packages with git dependencies · Issue #18557 · denolan...
On Arch Linux using the Arch Communty Repository deno, after upgrading to canary (which seems to be already done for the package) it does not work when i try to import npm:activitypub-express@4.2.2...
Ttmcw9/13/2023
that's been a fairly tough one to work with - with val.town at least there are certain dependencies that just break the evaluation server until it restarts, though evaluations are happening in a Worker
Ttmcw9/13/2023
Another issue for another part of this - doesn't seem like "" + works for npm: packages - https://github.com/denoland/deno/issues/20479
GitHub
Can't dynamically import an npm module with static analysis off · I...
With the following code: await import("" + "npm:got"); I get: ➜ git:(v3) ✗ deno run foo.mjs error: Uncaught (in promise) TypeError: Loading unprepared module: npm:got, imported ...

Looking for more? Join the community!

Recommended Posts
Using Deno in Frontend.Hey, I was wandering if it is possible to use Deno for Vanilla Frontend development. I dont want to Excluding certain directories when using "walk"Hello, I'm writing a script that should crawl through a directory and search for a given text insideSyntax Error: Unexpected token 'export'Hello, We are using Supabase Deno Edge Functions and are getting this error while trying to import aDeno Deploy QuestionsHey there. We are using Supabase to run edge functions, which in turn built their feature on top of Bunle OAK static assets to the compiled binaryHi, I am currently switching from NodeJS to Deno, and so far so good! One of the reasons for this sThe requested module does not provide an export named 'default'I'm trying to export the following interface: ```import User from '../models/User.ts'; export defaI want to contribute to deno without disturbing my libs in linux . Is there a way?**Noob alert** I have been trying to contribute to deno . So i followed these instructions https://dTimezones in Dates?Hi everyone, what's the right way to create a `Date` with a specific timezone?Resolving Class constructor errorHello, I am currently trying to port a small test api from NodeJS to Deno. This code uses only NPM pKV list is returning an empty iterator, but data is there and gettable via getHello. To simplify things, I am setting a key of `["accounts", account.name]` but when I try to get Read permission & NPM importsHello, I'm using `--allow-read=.` to allow a script to read files in the current directory. The scriWebSocket connections killing setInterval()Hey Deno friends, it appears that websocket connections are somehow stopping the execution of setIntjsx in jsAll of my files containing JSX are in `.js` files. Is there an easy fix for this when running?http errorI need help because I have a service that has more than 1 million requests per day and for about 7 ddoes Deno vscode support nesting `deno.json`?There is a project I'm working on has nesting `deno.json` files. The parent `deno.json` is a bit outDeploy says Worker not defined for ESBuild (wasm.js)@Deno AI Helper I am having trouble understanding how to get the esbuilder to work on Deno Deploy, u