Joh*_*yte 5 node.js webpack next.js
我添加了以下代码以next.config.js从客户端构建中排除麻烦的节点模块:
if (!isServer) {
config.node = {
fs : 'empty',
net :'empty',
express: 'empty'
}
}
Run Code Online (Sandbox Code Playgroud)
然后我得到了错误TypeError: Cannot read property 'prototype' of undefined。通过上述配置,只有 NodeJS 本机库(如“fs”和“net”)被排除在客户端构建之外,但外部库(如 Express)除外。那么如何排除 Express(取决于“fs”和“net”模块)?
此问题来源: https: //github.com/zeit/next.js/issues/9976
UPD:我还尝试将 webpack 配置设置为nodeExternals()客户端构建外部(当isServer为 false 时)。但在浏览器控制台中我收到此错误:
Uncaught ReferenceError: require is not defined
at Object.@babel/runtime-corejs2/helpers/interopRequireDefault (interopRequireDefault":1)
at __webpack_require__ (bootstrap:792)
at fn (bootstrap:150)
at Object.<anonymous> (next-dev.js:1)
at Object../node_modules/next/dist/client/next-dev.js (next-dev.js:13)
at __webpack_require__ (bootstrap:792)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.js?ts=1578410502794:1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1371 次 |
| 最近记录: |