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

node:module register is not a function #23201

Open
ry opened this issue Apr 3, 2024 · 4 comments
Open

node:module register is not a function #23201

ry opened this issue Apr 3, 2024 · 4 comments

Comments

@ry
Copy link
Member

ry commented Apr 3, 2024

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 ry added the node compat label Apr 3, 2024
@bartlomieju
Copy link
Member

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.

@marvinhagemeister
Copy link
Contributor

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
Copy link
Contributor

The the observable package only used module.register() to add support for running TS code, this works now thanks to #24965 . There the function is merely stubbed, but that's enough to unblock observable.

@terrablue
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants