I want to use this npm package in a service that currently works. When I run "npm run start", it fails and I get the error :
TypeError: wsc.require is not a function at Object../node_modules/hyco-ws/lib/HybridConnectionWebSocketServer.js (D:\FreshClones\beconnect5******\lib\main.js:80851:24) at webpack_require (D:\FreshClones\beconnect5******\lib\main.js:21:30) at Object../node_modules/hyco-ws/index.js (D:\FreshClones\beconnect5******\lib\main.js:80686:20) at webpack_require (D:\FreshClones\beconnect5******\lib\main.js:21:30) at Object../source/backend/azure/EventGridClient.ts (D:\FreshClones\beconnect5******\lib\main.js:235598:20) at webpack_require (D:\FreshClones\beconnect5******\lib\main.js:21:30) at Object../source/backend/main.ts (D:\FreshClones\beconnect5\i******\lib\main.js:236679:27) at webpack_require (D:\FreshClones\beconnect5******\lib\main.js:21:30) at Object.0 (D:\FreshClones\beconnect5******\lib\main.js:238511:18) at webpack_require (D:\FreshClones\beconnect5******\lib\main.js:21:30) [web-serv] [nodemon] app crashed - waiting for file changes before starting...
This is lines of code that are producing the error in the main.js file :
var wsc = __webpack_require__.c[/*require.resolve*/(/*! ws */ "./node_modules/hyco-ws/node_modules/ws/index.js")]
const Extensions = wsc.require('./lib/Extensions');
Note "******" this refers to a foldername which I am hiding for privacy reasons.
So I solved it myself, it was very simple.
We had a webpack.config.backend.js setup which was exporting modules into the lib folder's node modules after "npm run build". Just had to add my package in the module.exports.
module.exports = {
externals: ['utf-8-validate', 'bufferutil',{
"hyco-ws": "hyco-ws",
.................. ,
.................. ,
}]
};