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

require('./util') will return the "native module" that register by goja_nodejs/util/module.go, expect is my util.js file. #35

Closed
zbysir opened this issue Sep 4, 2022 · 1 comment

Comments

@zbysir
Copy link

zbysir commented Sep 4, 2022

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].

@zbysir
Copy link
Author

zbysir commented Sep 4, 2022

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

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

1 participant