D
Deno

help

esm_entry_point / extension macro; ReferenceError

Bbaphomet_the_traveller9/21/2023
How do I use esm_entry_point properly? I defined my extension as:
extension!(
ext_name,
ops = [op_register_entrypoint],
esm_entry_point = "ext:ext_name/js_playground.js",
esm = [ dir "src/ext", "ext_name.js" ],
);
extension!(
ext_name,
ops = [op_register_entrypoint],
esm_entry_point = "ext:ext_name/js_playground.js",
esm = [ dir "src/ext", "ext_name.js" ],
);
But I'm now getting a referenceerror about ext_name being undefined - which is odd since I can see it expands to define the struct
DAHDeno AI Helper9/21/2023
I'm sorry, but the documentation does not provide a clear answer to your question about using esm_entry_point properly. It would be helpful to have more context or see more of your code to understand the issue better. However, based on the code snippet you provided, it seems like you're trying to define an extension with a JavaScript entry point. Please ensure that the JavaScript file specified in esm_entry_point exists at the correct path and is properly exported. Also, make sure that the ext_name you're using in your Rust code matches the name of the JavaScript module you're trying to import. If you're still having issues, it might be helpful to debug by checking the paths and names in your code, or by trying to isolate the problem in a smaller piece of code. If the problem persists, please provide more details about your setup and the error message you're seeing.
Bbaphomet_the_traveller9/21/2023
Yeah that's not super helpful @mmastrac Hate to bother you again, but you seem to be very familiar with the extensions module
Mmmastrac9/21/2023
Hmm, that's odd. Are you able post the code? This looks very similar to what we see in the CLI extension:
deno_core::extension!(cli,
deps = [runtime],
ops = [op_npm_process_state],
esm_entry_point = "ext:cli/99_main.js",
esm = [
dir "js",
"40_testing.js",
"99_main.js"
],
deno_core::extension!(cli,
deps = [runtime],
ops = [op_npm_process_state],
esm_entry_point = "ext:cli/99_main.js",
esm = [
dir "js",
"40_testing.js",
"99_main.js"
],
Bbaphomet_the_traveller9/22/2023
That's the example I used haha Gimme a sec I'll drop it in a gist https://gist.github.com/rscarson/72aa99b910e9f1427d15ce6563d0b888 Here's the relevant file I declare the extension on line 30, then use it to build the runtime with vec![js_playground::init_ops_and_esm()]; on 44 The rest of it is here: https://github.com/rscarson/js-playground (it's part of a larger project to migrate a platform I maintain to use deno on the backend) A lot of the samples I see use customize to set the specifiers to that format... what's the default specifier? I'm guessing that's the problem Oh wait a second - I'm a moron It's not a rust error - its a JS error The extension entrypoint never runs so the globalThis.js_playground object is never set
Mmmastrac9/22/2023
Ah yeah, it looks like something needs to call load ๐Ÿ™‚
Bbaphomet_the_traveller9/22/2023
js_playground::init_ops_and_esm() isn't sufficient? where do I call load Is that a rust or JS thing
Mmmastrac9/22/2023
It's a JS thing. You could probably just remove the load function wrapper and run that JS directly
Bbaphomet_the_traveller9/22/2023
Ah yeah I see the wrapper it generates - how do I turn that off?
Mmmastrac9/22/2023
What if you change js_playground.js to this?
export function load() {
globalThis.js_playground = {
'register_entrypoint': (f) => Deno.core.ops.op_register_entrypoint(f)
};
}

load()
export function load() {
globalThis.js_playground = {
'register_entrypoint': (f) => Deno.core.ops.op_register_entrypoint(f)
};
}

load()
Bbaphomet_the_traveller9/22/2023
Oh I'm dumb - load is my function It's aliiiiiiive! Thanks for all the help! If I can make a small request though - it'd be nice if the extension! macro could have an option to not add pub It doesn't document the functions it builds, which breaks my lints I wrapped it in a mod block but that's a little clunky
Mmmastrac9/22/2023
We would totally take a PR if you'd like to PR a fix to make the doc lints work. Ideally we would be able to drop a doc comment on the extension block itself.
Bbaphomet_the_traveller9/22/2023
Sure! I'll work on one this aft So init_js_only is for CJS, init_ops_and_esm is for use with ES modules, and init_ops only preps the ops, bypassing any sources attached to the extension? Alrighty just making sure the CI and fmt checks still pass then I'll put my PR through
Mmmastrac9/22/2023
It's a bit complicated, but those methods are used for the various snapshotting states we have while building Deno. If you don't use snapshots, I believe you can use init_ops_and_esm() everywhere
Bbaphomet_the_traveller9/22/2023
GitHub
Add documentation options for extension! by rscarson ยท Pull Request...
Added docs: comma separated list of toplevel #[doc=...] tags to be applied to the extension's resulting struct to extension! to allow users to set docblocks for it, since the struct is always m...
Bbaphomet_the_traveller9/22/2023
Also included a small example showing op2/extension!() Since there's few places in the codebase that builds and uses extensions in a concise way, I can remove it if that's out of line

Looking for more? Join the community!

Recommended Posts
remoteAddr returning localhost on Deno DeployI saw this thread (https://discord.com/channels/684898665143206084/1055631150787334184) about gettinDeno-native Nuxt.js?The recent [The State of Web Frameworks on Deno](https://deno.com/blog/web-frameworks-on-deno) blogDeno support Fleet IDE?Hello, can the deno plug-in be used on the Fleet editor of JetBrains IDEs? Thank you.Async execution contextIs there any way I can create a global that is unique to an async operation? I would like to use thaError Deploying to Deno Deploy LODASH isEmpty.jsI am having issues deploying to deno deploy. All was well 3 days ago. Made some changes today - but need to refersh page for message each time a user from different country sends a messageHey I was going through the below deno chat app and found a bug which is the need to referesh the paAPI architecture for generic callbackHi there, I have a general question about code architecture for an API I'm doing. Basically, it listHow can I run `deno test` on all `*.spec.ts` files contains in a specific directory ?Everything is in the question, it seems very strange that we do not have a `pattern` option to speciuseEffect in the islandsSeeing a strange error in the browser window as soon as I add a simple as ```ts useEffect(() => { Basic react server side rendering does not work on Deno Deploy but does locallyThe below application work correctly locally but fails on Deno Deploy. On Deno Deploy, all my responode cryptoHey everyone, can you explain why certain packages such as node/crypto are not included in newer verPretty new to Deno, what is the recommended way to create a monorepo-like in Deno ?Everything is in the question. I tried during the entire week-end to get up & running with monorepo-[fresh] injecting css into head in a componentWhen I inject css in the head of my html in a component, it works perfectly, but when I reuse the coAutosave firing on editing `.ts` files when a separate Deno enabled project is openHello, I am working on slack automation using deno. I'm developing with webstorm, but I'm having a pProblem with parsing `base64url` from a `Buffer (node)`help , it works in bun but not in Deno, I don't know if is a bug from them or it's not implemented hUUID of managed KV databaseHello, I am trying to follow [this doc](https://docs.deno.com/kv/manual/on_deploy#connect-to-managedError at the execution of a programmHey ! I have a problem when i run one of my programm with deno, is a programm made with typescript Can't import typescript moduleWhy can I only import the js file and not the ts file? ```js import * as zip from "https://deno.lanIs there a way to change the default Details of the compiled exeI esentialy want to change the comiling defaults of the details and the image of the resulting exe (Setting source map root with `deno_emit`Hello! I'm currently trying to use `deno_emit` so bundle some assets. The code bundles properly, how