Getting TypeError: wsc.require is not a function for hyco-ws npm package

Getting TypeError: wsc.require is not a function for hyco-ws npm package

我想在当前可用的服务中使用这个 npm 包。当我 运行 "npm run start" 时,它失败了,我得到错误:

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...

这是在 main.js 文件中产生错误的代码行:

var wsc = __webpack_require__.c[/*require.resolve*/(/*! ws */ "./node_modules/hyco-ws/node_modules/ws/index.js")]

const Extensions = wsc.require('./lib/Extensions');

注意“******”指的是我出于隐私原因隐藏的文件夹名称。

所以我自己解决了,很简单

我们有一个 webpack.config.backend.js 设置,它在 "npm run build" 之后将模块导出到 lib 文件夹的节点模块中。只需将我的包裹添加到 module.exports.

    module.exports =  {
       externals:  ['utf-8-validate', 'bufferutil',{
          "hyco-ws": "hyco-ws",
           .................. ,
           .................. ,
           }]
     };