0

我正在尝试部署我的应用程序,它是 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
    }
  })

现在.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>

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

4

1 回答 1

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

于 2019-07-08T06:43:04.883 回答