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

ES modules InvokeFromStringAsync #201

Open
stephenlautier opened this issue Sep 10, 2024 · 2 comments
Open

ES modules InvokeFromStringAsync #201

stephenlautier opened this issue Sep 10, 2024 · 2 comments

Comments

@stephenlautier
Copy link

Hi,

I'm trying to invoke an .mjs or ES module from a string is this somehow possible?

I've seen this issue and from file should be supported #151

However in this case, I'm using a class library and the file is an Embedded Resource, so then its invoked with InvokeFromStringAsync

[10:54:39 WRN] [Jering.Javascript.NodeJS.HttpNodeJSService] An invocation attempt failed. Retries using existing process remaining: 0.
Exception:
  Jering.Javascript.NodeJS.InvocationException: Unexpected token 'export'
anonymous:2
export default async (
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1274:20)
    at Module._compile (node:internal/modules/cjs/loader:1320:27)
    at IncomingMessage.<anonymous> (file:///S:/git/rig/midgard.pwa/[eval1]:170:21)
    at IncomingMessage.emit (node:events:517:28)
    at endReadableNT (node:internal/streams/readable:1400:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
   at Jering.Javascript.NodeJS.HttpNodeJSService.TryInvokeAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken)
   at Jering.Javascript.NodeJS.OutOfProcessNodeJSService.TryInvokeCoreAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken)

Any help would be appreciated thank you 🙇‍♂️

@stephenlautier stephenlautier changed the title ESM modules InvokeFromStringAsync ES modules InvokeFromStringAsync Sep 10, 2024
@Curlack
Copy link

Curlack commented Oct 24, 2024

From the error it seems you may have used module.export instead of module.exports? <-- Note the "s" at the end of exports

@stephenlautier
Copy link
Author

No its an esm not cjs (so no exports)

the export is export default async (

I found a solution to this and might be better actually in this case

Basically having the mjs file as EmbededResource -> convert to string -> write file (in host) and invoke it as a file - ESM is supported that way and it avoids the transfer of the script as string + compile which is done in this library (so I believe its more efficient)

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

No branches or pull requests

2 participants