Open nzedler opened 2 months ago
The ziti.js
else-statement can NEVER work in environments with Webpack, see the official answer https://github.com/mapbox/node-pre-gyp/issues/308#issuecomment-413556240 to the question if node-pre-gyp can support Webpack.
It seems to me that we have to modify the if-statement to allow Webpack environments (or somehow fulfill the if-statement when running import ziti from '@openziti/ziti-sdk-nodejs'
, but I have no clue how)
Hi together,
we're having trouble getting ziti-sdk-nodejs working without modifying the ziti-sdk-nodejs library code under Nextjs (React). We built and call the following test function using the ESM-client-side example code server-side:
In order to get it working, we needed to add the dependency
node-loader
and the following Webpack config in thenext.config.js
. What we did is copying theziti_sdk_nodejs.node
-file to the build directory to make it available (since Nextjs performs build optimization). Additionally we hat to define the node-loader, that is able to load the binary:Running this example, we get the following error message:
This is because in
@openziti/ziti-sdk-nodejs/lib/ziti.js
line 32 to 44, always theelse
-statement is used.typeof require.context == 'function'
is never true, becauserequire
is undefined:However, if we modify the if-statement to always true,
require.context("../build/", true, /\.node$/)
works and loads the binary despitetypeof require.context == 'function'
being false. This works flawlessly. 🎉We don't want to modify the package source in production. Are there any possibilities to get it running without modifying the package source?