Created
December 17, 2024 13:43
-
-
Save erdesigns-eu/6b47d6b3d1077efb2c0c080fc94f8e80 to your computer and use it in GitHub Desktop.
Runtime require function to fix loading native .node modules when using PKG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function is used to load the native .node module. Since webpack replaces the native require function, | |
* we need to get the original require function from the global scope. | |
* | |
* Found this code here: https://github.com/prebuild/node-gyp-build/blob/master/node-gyp-build.js | |
*/ | |
// @ts-ignore | |
const runtimeRequire = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require | |
const nativeModule = runtimeRequire('./path/to/module.node'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment