I have a custom source loader which loads modules from a remote source and upon updating this package spotted an issue when loading native modules.
Due to https://github.com/dop251/goja_nodejs/pull/36 it now tries to download the module from the remote source before attempting to load the native module and this log should highlight the issue with that:
It's making 12 HTTP requests before attempting to load the native module!
Possible workarounds could be either making the priority configurable through an option on require.NewRegistry, or introducing a sentinel error that tells the resolver to stop looking and move on to attempting to load the module from the native modules. My preference would be implementing both! Happy to submit a PR if this is something you'd merge.
I've just realised the originally proposed fix in #36 was more correct. The 'core' module should be preferred, but the name of the module should not be normalised prior to the resolution.
I have a custom source loader which loads modules from a remote source and upon updating this package spotted an issue when loading native modules.
Due to https://github.com/dop251/goja_nodejs/pull/36 it now tries to download the module from the remote source before attempting to load the native module and this log should highlight the issue with that:
JS script:
Log output:
It's making 12 HTTP requests before attempting to load the native module!
Possible workarounds could be either making the priority configurable through an option on
require.NewRegistry
, or introducing a sentinel error that tells the resolver to stop looking and move on to attempting to load the module from the native modules. My preference would be implementing both! Happy to submit a PR if this is something you'd merge.