我正在尝试部署我的应用程序next.js + express服务器,只是为了处理一些套接字连接。
这是我的项目目录的样子:
next.config.js:
const withCSS = require('@zeit/next-css')
module.exports = withCSS({
webpack: config => {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]'
}
}
})
return config
}
})
now.json:
{
"version": 2,
"builds": [
{"src": "package.json", "use": "@now/next"},
{ "src": "server.js", "use": "@now/node" }
]
}
package.json的脚本部分:
"scripts": {
"now-build": "next build",
"dev": "node server.js",
"build": "next build",
"start": "cross-env NODE_ENV=production node server.js"
}
我得到的错误: server.js:
Error: No serverless pages were built. https://err.sh/zeit/now-builders/now-next-no-serverless-pages-built
at Object.exports.build (/tmp/26a0d565/.build-utils/.builder/node_modules/@now/next/dist/index.js:275:19)
at <anonymous>
package.json:
UnhandledPromiseRejectionWarning: TypeError: Data must be a string or a buffer
at Hash.update (crypto.js:99:16)
at ids.forEach.id (/tmp/2d245f3b/node_modules/next/dist/build/webpack/plugins/hashed-chunk-ids-plugin.js:24:41)
如果我按照链接上的说明进行操作,发现无服务器错误,我仍然会遇到相同的错误。
const withCSS = require('@zeit/next-css')
module.exports = withCSS({
target: 'serverless',
webpack: config => {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]'
}
}
})
return config
}
})
如果我删除now.json然后部署它只是在页面上列出文件夹。互联网上关于这些错误的信息很多,但我无法解决
答案 0 :(得分:0)
尝试以下方法。
const withCSS = require("@zeit/next-css");
const cssConfig = withCSS({
webpack: config => {
config.module.rules.push({
test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
use: {
loader: "url-loader",
options: {
limit: 100000,
name: "[name].[ext]"
}
}
});
return config;
}
});
module.exports = Object.assign(cssConfig, { target: "serverless" });
我认为配置未正确合并。如果配置中存在console.log(cssConfig)
,则可以通过target:serverless
进行快速检查。