小编Joh*_*yte的帖子

如何从 Next.js 应用程序的客户端构建中排除服务器端模块(如 Express)?

我添加了以下代码以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)

node.js webpack next.js

5
推荐指数
0
解决办法
1371
查看次数

Heroku 应用程序崩溃状态 503。可能会出现哪些问题?

我尝试将全栈应用程序从 GitHub 部署到 Heroku,但收到 503 错误,尽管它在本地计算机上运行良好。可能会出现哪些问题?

2019-03-05T09:04:17.530233+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=message-board-byjb.herokuapp.com request_id=0f57c216-cf0e-46fa-a8fd-1e003b29e0ac fwd="85.26.235.56" dyno= connect= service= status=503 bytes= protocol=https
2019-03-05T09:04:17.999176+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=message-board-byjb.herokuapp.com request_id=420d10af-fd3b-43b7-ab5b-9c925e6e520b fwd="85.26.235.56" dyno= connect= service= status=503 bytes= protocol=https
2019-03-05T09:06:10.224358+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=message-board-byjb.herokuapp.com request_id=5c7b5ba0-3e8a-4e4c-9a4c-38e7e3c47079 fwd="85.26.235.56" dyno= connect= service= status=503 bytes= protocol=https
2019-03-05T09:06:10.714879+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=message-board-byjb.herokuapp.com request_id=7eca85fd-6018-41d7-897a-5fbf1b40fcbb fwd="85.26.235.56" dyno= connect= service= status=503 bytes= protocol=https
2019-03-05T09:06:13.775830+00:00 heroku[router]: at=error code=H10 desc="App crashed" …
Run Code Online (Sandbox Code Playgroud)

javascript deployment heroku node.js

4
推荐指数
1
解决办法
5196
查看次数

标签 统计

node.js ×2

deployment ×1

heroku ×1

javascript ×1

next.js ×1

webpack ×1