AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
246 stars 23 forks source link

Require @grpc/grpc-js fails on httpyac.config.js #325

Open mniak opened 2 months ago

mniak commented 2 months ago

I have a server whose certificate name does not match the dns name. So I have been using the following code inside the .http file to skip cert verification:

{{@request
const grpc = require('@grpc/grpc-js');
request.channelCredentials = grpc.ChannelCredentials.createSsl(null, null, null, { 
  checkServerIdentity: () => undefined,
});
}}

But since there are various files, I was trying to move this config to a hook into the httpyac.config.js file. But when requireing '@grpc/grpc-js' there, it complains that the module could not be found. That shouldn't be the case, since the module indeed is already somewhere in order to work during the request.

2024-08-30 11:34:41.802 [error] error in .httpyac.js Cannot find module '@grpc/grpc-js'
Require stack:
- /Users/username/myproj/examples/httpyac.config.js
- /Users/username/myproj/examples/package.json
Error: Cannot find module '@grpc/grpc-js'
Require stack:
- /Users/username/myproj/examples/httpyac.config.js
- /Users/username/myproj/examples/package.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1152:15)
    at i._resolveFilename (node:electron/js2c/utility_init:2:13405)
    at Module._load (node:internal/modules/cjs/loader:993:27)
    at c._load (node:electron/js2c/node_init:2:13801)
    at E._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:177:6051)
    at i._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:174:31787)
    at o._load (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:139:34334)
    at Module.require (node:internal/modules/cjs/loader:1240:19)
    at g (/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js:2:647)
    at configureHooks (/Users/username/myproj/examples/httpyac.config.js:3:22)
    at pJ.configureHooks (/Users/username/.vscode/extensions/anweber.vscode-httpyac-6.15.1/dist/extension.js:177:46549)
    at pJ.initHttpFile (/Users/username/.vscode/extensions/anweber.vscode-httpyac-6.15.1/dist/extension.js:177:46206)
    at async pJ.parse (/Users/username/.vscode/extensions/anweber.vscode-httpyac-6.15.1/dist/extension.js:177:45273)
AnWeber commented 2 weeks ago

@mniak The simplest solution is to simply install the dependency yourself. I currently load the file using module.require. But I can't inject my own packages via this API, or I don't know at the moment. I'll check what options I have, but I'll need time for that as I don't know the API very well.