Closed cspotcode closed 3 years ago
Here is where I'm encountering this failure:
@swc/core
is calling loadBinding
:
https://github.com/swc-project/swc/blob/master/node-swc/src/index.ts#L14
The dependencies are declared for @swc/core
, so they can be require()
d by @swc/core
but not by @node-rs/helper
https://github.com/swc-project/swc/blob/master/package.json#L80-L85
In yarn2, any module you attempt to
require()
must be declared as a dependency in your own package.json. This means when@node-rs/helper
attempts to, for example,require('@swc/core-linux')
, it fails, because@swc/core-linux
is not a dependency of@node-rs/helper
Fortunately, I think the solution is simple.
@node-rs/helper
needs to accept the caller'srequire
function as an argument. Then when trying torequire
modules, it will use the caller'srequire
, which is able to resolve the caller's dependencies. This is what we want, since we want to be sure that the modules we load match the versions that the caller wants to use.For backwards compatibility, this can be optional, but it will probably cause issues with yarn 2 until the callers are updated to pass in a
require
function.