我安装了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建立套接字关系,但是它向我发送了这些错误,甚至不允许我运行套接字。我该如何解决?
答案 0 :(得分:0)
只需在webpack.mix.js中添加此行
target: "node",
externals: {
express: 'express',
},