【问题标题】:Critical dependency: the request of a dependency is an expression for socket.io and express关键依赖:依赖的请求是socket.io和express的表达式
【发布时间】:2019-05-04 15:08:57
【问题描述】:

我安装了 Laravel 并运行 npm run watch 命令,它返回:

ERROR in ./node_modules/destroy/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\xampp\htdocs\checknpm\node_modules\destroy'

ERROR in ./node_modules/express/lib/request.js
Module not found: Error: Can't resolve 'net' in 'C:\xampp\htdocs\checknpm\node_modules\express\lib'

ERROR in ./node_modules/engine.io/lib/server.js
Module not found: Error: Can't resolve 'uws' in 'C:\xampp\htdocs\checknpm\node_modules\engine.io\lib'

然后我在laravel中设置了一些配置webpack.mix.js:

mix.webpackConfig({
    target: "node",
});

然后它重新调整:

WARNING in ./node_modules/socket.io/lib/index.js
113:11-32 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/node-gyp-build/index.js
13:9-32 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/node-gyp-build/index.js
20:15-54 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/express/lib/view.js
81:13-25 Critical dependency: the request of a dependency is an expression

ERROR in ./node_modules/engine.io/lib/server.js
Module not found: Error: Can't resolve 'uws' in 'C:\xampp\htdocs\checknpm\node_modules\engine.io\lib'

最后我补充说:

mix.webpackConfig({
    target: "node",
    externals: {
        uws: "uws",
        ws: "ws",
    },
});

当我运行 npm run watch 时它返回:

WARNING in ./node_modules/socket.io/lib/index.js
113:11-32 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/socket.io/lib/index.js
 @ ./resources/js/bootstrap.js
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/sass/app.scss

WARNING in ./node_modules/express/lib/view.js
81:13-25 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/express/lib/view.js
 @ ./node_modules/express/lib/application.js
 @ ./node_modules/express/lib/express.js
 @ ./node_modules/express/index.js
 @ ./resources/js/bootstrap.js
 @ ./resources/js/app.js
 @ multi ./resources/js/app.js ./resources/sass/app.scss

我尝试了不同的方法,但没有奏效!我想与 Laravel 建立套接字关系,但是它向我发送了这些错误,甚至不允许我运行套接字。我该如何解决?

【问题讨论】:

  • 第一次运行npm install
  • 我已经运行了它,但我又按照你说的再次运行它但没有结果:(
  • 我可以看到这些重新警告,这里没有错误
  • 在socket编程过程中不会出问题吗?

标签: node.js laravel npm webpack laravel-mix


【解决方案1】:

只需在 webpack.mix.js 中添加这一行

        target: "node",
    externals: {
        express: 'express',

    },
  

【讨论】:

    猜你喜欢
    • 2016-08-28
    • 2017-08-11
    • 2020-06-15
    • 2020-10-11
    • 1970-01-01
    • 2022-11-10
    • 2022-08-15
    • 2021-06-13
    • 2018-10-10
    相关资源
    最近更新 更多