-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Version: Deno 2.4.5
I came across this issue in the context of nbb, a scripting environment using ClojureScript on Node.js and deno.
When a user loads a library in nbb, the implementation roughly goes as follows in Node.js. Assume there is a node_modules
folder with the "ws"
library installed in /tmp/repro
.
const x = import.meta.resolve("ws")
console.log(x);
const ws = await(import(x));
When executing this script from /tmp/repro
with deno -A repro.mjs
this prints:
file:///private/tmp/repro/node_modules/ws/wrapper.mjs
and succesfully loads the library in Deno.
If however I execute the dynamic import of the same file URL from another directory, which is often the case in nbb since nbb can be loaded from jsr:
for example, it fails in Deno. This can be simulated with the following:
Create this script repro.mjs
in /tmp
where there is no node_modules
directory:
const ws = await(import('file:///private/tmp/dude/node_modules/ws/wrapper.mjs'));
console.log(ws);
Here I'm getting:
/tmp $ deno -A repro.mjs
error: Uncaught (in promise) SyntaxError: The requested module './lib/receiver.js' does not provide an export named 'default' at file:///private/tmp/dude/node_modules/ws/wrapper.mjs:2:8
const ws = await(import('file:///private/tmp/dude/node_modules/ws/wrapper.mjs'));
^
at async file:///private/tmp/repro.mjs:1:12
It seems Deno is trying to load the file and follow the import from ws/wrapper.mjs
but fails.
When running the same file with Node.js it works flawlessly.