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

GoError: Invalid module at github.com/dop251/goja_nodejs/require.(*RequireModule).require-fm (native) #73

Open
chrisroy87 opened this issue Feb 27, 2024 · 1 comment

Comments

@chrisroy87
Copy link

I have a very basic program, trying out this library before actually incorporating it into my project.

`script, err := os.ReadFile("algos/sample_plugin/sample_plugin.js")
if err != nil {
panic(err)
}

// Read the program into memory
program, err := goja.Compile("sample_plugin", string(script), true)
if err != nil {
	fmt.Println("Error compiling JavaScript program:", err)
	return
}

vm := goja.New()
vm.SetFieldNameMapper(goja.TagFieldNameMapper("json", true))
registry := new(require.Registry) // this can be shared by multiple runtimes
registry.Enable(vm)

// now run the program
_, err = vm.RunProgram(program)
if err != nil {
	panic(err)
}

predict, ok := goja.AssertFunction(vm.Get("predict"))
if !ok {
	fmt.Println("could not get predict")
	return
}`

When I try to run this, I get the following errors:
GoError: Invalid module at github.com/dop251/goja_nodejs/require.(*RequireModule).require-fm (native)

Things I have tried:

  1. Remove and Re-install both goja and goja_nodejs
  2. Update using go mod tidy.

Can some one please help me?

@dop251
Copy link
Owner

dop251 commented Mar 5, 2024

Try adding this before panic(err):

if ex, ok := err.(*goja.Exception); ok {
    panic(ex.String())
}

This should give you the full stack trace, which should point to a line with the offending require

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