Closed zbysir closed 2 years ago
This code will show the problem
import ( "github.com/dop251/goja" "github.com/dop251/goja_nodejs/console" "github.com/dop251/goja_nodejs/require" "testing" ) func TestRegistryUtil(t *testing.T) { vm := goja.New() require.NewRegistry().Enable(vm) console.Enable(vm) v, err := vm.RunScript("root.js", "require('./util')") if err != nil { panic(err) } t.Logf("%+v", v.Export()) }
util.js
exports.default = "1";
It will print map[format:0x13b84c0] instead of map[default: 1].
map[format:0x13b84c0]
map[default: 1]
The reason for the error is path.Clean("./util") will return "util" in https://github.com/dop251/goja_nodejs/blob/master/require/resolve.go#L15
path.Clean("./util")
"util"
This code will show the problem
util.js
It will print
map[format:0x13b84c0]
instead ofmap[default: 1]
.