You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
'use server';importzitifrom'@openziti/ziti-sdk-nodejs';exportasyncfunctionTestZiti(){// Somehow provide path to identity file, e.g. via env varconstzitiIdentityFile=process.env.ZITI_IDENTITY_FILE??'./test_identity.json';// Authenticate ourselves onto the Ziti networkawaitziti.init(zitiIdentityFile).catch((err)=>{/* probably exit */});conston_resp_data=(obj)=>{console.log(`response is: ${obj.body.toString('utf8')}`);};// Perform an HTTP GET request to a dark OpenZiti web serviceziti.httpRequest('myDarkWebService',// OpenZiti Service name or HTTP origin part of the URLundefined,// schemeHostPort parm is mutually-exclusive with serviceName parm'GET','/',// path part of the URL including query params['Accept: application/json'],// headersundefined,// optional on_req cb undefined,// optional on_req_data cbon_resp_data// optional on_resp_data cb);}
In order to get it working, we needed to add the dependency node-loader and the following Webpack config in the next.config.js. What we did is copying the ziti_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:
⨯ ./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <!doctype html>
| <html>
| <head>
Import trace for requested module:
./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/util/nw-pre-gyp/index.html
./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/ sync ^\.\/.*$
./node_modules/.pnpm/@[email protected]/node_modules/@mapbox/node-pre-gyp/lib/node-pre-gyp.js
./node_modules/.pnpm/@[email protected]/node_modules/@openziti/ziti-sdk-nodejs/lib/ziti.js
./src/app/test.tsx
./src/app/page.tsx
This is because in @openziti/ziti-sdk-nodejs/lib/ziti.js line 32 to 44, always the else-statement is used. typeof require.context == 'function' is never true, because require is undefined:
However, if we modify the if-statement to always true, require.context("../build/", true, /\.node$/) works and loads the binary despite typeof require.context == 'function' being false. This works flawlessly. 🎉
// if (typeof require.context == 'function') {if(true){importAll(require.context("../build/",true,/\.node$/));}else{constbinary=require('@mapbox/node-pre-gyp');constpath=require('path')constbinding_path=binary.find(path.resolve(path.join(__dirname,'../package.json')),{debug: false});binding=require(binding_path);}
We don't want to modify the package source in production. Are there any possibilities to get it running without modifying the package source?
The text was updated successfully, but these errors were encountered:
The ziti.js else-statement can NEVER work in environments with Webpack, see the official answer mapbox/node-pre-gyp#308 (comment) 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?
The text was updated successfully, but these errors were encountered: