deno icon indicating copy to clipboard operation
deno copied to clipboard

node:module register is not a function

Open ry opened this issue 1 year ago • 4 comments

Version: deno 1.42.1+92a8ada

https://nodejs.org/docs/latest/api/module.html#moduleregisterspecifier-parenturl-options

# npm init @observablehq
# cd hello-framework
# deno task dev --debug
Task dev observable preview "--debug"

Unexpected error: N.register is not a function
The full error follows

error: Uncaught (in promise) TypeError: N.register is not a function
    at C (file:///Users/ry/src/hello-framework/node_modules/.deno/@[email protected]/node_modules/tsx/dist/esm/index.mjs:1:695)
    at file:///Users/ry/src/hello-framework/node_modules/.deno/@[email protected]/node_modules/tsx/dist/esm/index.mjs:5:1913

ry avatar Apr 03 '24 10:04 ry

This is trouble, it's essentially custom loaders: https://nodejs.org/docs/latest/api/module.html#customization-hooks that need to be executed before the actual code is executed.

bartlomieju avatar Apr 03 '24 10:04 bartlomieju

I wonder if it might be best to bypass this module somehow. The sole purpose of the tsx module is to allow node to work natively with TypeScript files.

marvinhagemeister avatar Apr 08 '24 12:04 marvinhagemeister

The the observable package only used module.register() to add support for running TS code, this works now thanks to https://github.com/denoland/deno/pull/24965 . There the function is merely stubbed, but that's enough to unblock observable.

marvinhagemeister avatar Aug 19 '24 06:08 marvinhagemeister

I would benefit from Deno supporting that. @bartlomieju FWIW, Node has a static and dynamic mode for that. With the --import flag, it indeed needs to run before any code is loaded, but programmatically (this issue's case), it can be executed at any time in the lifecycle of the program, but then only applies to thereafter dynamically imported modules.

Interestingly enough, normal (static) imports from post-registration dynamically loaded modules seem to also work in my tests.

terrablue avatar Aug 19 '24 22:08 terrablue