tmcw
tmcw17mo ago

Using dynamic import with npm compatibility gives intermittent error "__DENO_NODE_GLOBAL_THIS_167935

This is pretty hard to google because the number at the end of the error changes everytime it happens, but basically: is this a known issue? I'll run some code (in a worker, using dynamic import pointing to npm: or a CDN and get ReferenceError: __DENO_NODE_GLOBAL_… on the first and sometimes second run, but after that it'll work.
5 Replies
bartlomieju
bartlomieju17mo ago
@tmcw that's definitely a bug! Could you provide some kind of reproduction? I have a feeling I know what's the issue, but I need a test case to pin point it
tmcw
tmcw17mo ago
Sure, I think I can do that
tmcw
tmcw17mo ago
Gist
repro.ts
GitHub Gist: instantly share code, notes, and snippets.
tmcw
tmcw17mo ago
This produces
error: Uncaught (in promise) ReferenceError: __DENO_NODE_GLOBAL_THIS_1679440099__ is not defined
at file:///Users/tmcw/Library/Caches/deno/npm/registry.npmjs.org/simple-statistics/7.8.2/dist/simple-statistics.mjs:1:18
error: Uncaught (in promise) ReferenceError: __DENO_NODE_GLOBAL_THIS_1679440099__ is not defined
at file:///Users/tmcw/Library/Caches/deno/npm/registry.npmjs.org/simple-statistics/7.8.2/dist/simple-statistics.mjs:1:18
okay, works for dynamic & static imports - the importing from a data url appears to be the cause tracked the internals down to https://github.com/denoland/deno/blob/7d9653d51fb0c4d3844f61e1214b6bddc50d2cef/ext/node/lib.rs#L401 - not like that's the cause okay i think i found a workaround - if you import something from npm on the top level before you import something from npm in an import, then it works filed a bug with the repro: https://github.com/denoland/deno/issues/18343
bartlomieju
bartlomieju17mo ago
thanks! yeah, that was exactly what I expected - we only initialize the node runtime if we discover the NPM dependency but data URLs were definitely missed on this I'll try to fix it before tomorrow's release, but no promises 🤞