dop251 / goja_nodejs

Nodejs compatibility library for Goja
MIT License
329 stars 78 forks source link

Misleading error message when registry is not enabled #31

Closed dop251 closed 2 years ago

dop251 commented 2 years ago

Discussed in https://github.com/dop251/goja/discussions/404

Originally posted by **pgundlach** July 12, 2022 I came across https://github.com/dop251/goja/issues/116 to enable `console.log()`, but when I use the command, I get an error ```js package main import ( "github.com/dop251/goja" "github.com/dop251/goja_nodejs/console" ) func main() { runtime := goja.New() console.Enable(runtime) } ``` returns (`go run main.go`) ``` go run main.go panic: TypeError: Please enable require for this runtime using new(require.Require).Enable(runtime) goroutine 1 [running]: github.com/dop251/goja_nodejs/require.Require(0x140001ba960?, {0x102737917, 0x7}) /Users/patrick/go/pkg/mod/github.com/dop251/goja_nodejs@v0.0.0-20220706223936-8bb8eec2f26a/require/module.go:198 +0x144 github.com/dop251/goja_nodejs/console.Enable(0x14000198000?) /Users/patrick/go/pkg/mod/github.com/dop251/goja_nodejs@v0.0.0-20220706223936-8bb8eec2f26a/console/module.go:75 +0x30 main.main() /Users/patrick/prog/go/goja/main.go:10 +0x38 exit status 2 ``` but ``` new(require.Require).Enable(runtime) ``` does not seem to be valid Go (require.Require (value of type func(runtime *goja.Runtime, name string) goja.Value) is not a type). What can I do to load the console module?