【问题标题】:How to deploy next.js + express app to Zeit now UnhandledPromiseRejectionWarning noserverpages built现在如何将 next.js + express 应用程序部署到 Zeit UnhandledPromiseRejectionWarning noserverpages built
【发布时间】:2019-11-14 16:15:54
【问题描述】:

我正在尝试部署我的应用程序,它是 next.js + express 服务器,只是为了处理一些套接字连接。

这是我的项目目录的样子:

下一个.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 然后部署它只是在页面上列出文件夹。互联网上有很多关于这些错误的信息,但我无法解决它

【问题讨论】:

  • 我认为现在 2 使用 now 1 是不可能的,但我不确定

标签: next.js vercel


【解决方案1】:

试试下面的。

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" });


我认为配置没有正确合并。如果配置中存在target:serverless,您可以通过console.log(cssConfig) 进行快速检查。

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 2020-06-15
    • 2019-12-05
    • 2019-10-30
    • 2019-10-11
    • 2019-07-22
    • 2017-05-06
    • 2021-06-24
    • 2023-03-15
    相关资源
    最近更新 更多