一个“routes-manifest.json"找不到 [英] A "routes-manifest.json" couldn't be found

查看:79
本文介绍了一个“routes-manifest.json"找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 本教程 以便我在 vercel 构建期间生成一个静态文件.我试过移动文件,但它总是显示如下日志:

I'm following this tutorial so that I generate a static file during the vercel build. I've tried moving the files around but it always shows a log like:

23:41:48.432 $ node ./pages/api/build.js 23:41:48.493 构建时间文件创建成功!23:41:48.495 在 0.09 秒内完成.23:41:48.507 错误:routes-manifest.json"找不到.这通常是由项目中的错误配置引起的.

然后它链接到this.我已经检查了问题,一切似乎都很好.

Then it links to this. I've checked the issues and everything seems to be fine.

如果我从 package.json 中删除 "vercel-build":"node ./pages/api/build.js" 行,错误就会消失.但还有功能..

If I remove the "vercel-build": "node ./pages/api/build.js" line from package.json, the error disappears. But also the functionality..

我的 pages/api/index.js 文件:

my pages/api/index.js file:

const BuiltTime = require('./built-time');
module.exports = (req, res) => {
  res.setHeader('content-type', 'text/plain');
  res.send(`
    This Serverless Function was built at ${new Date(BuiltTime)}.
    The current time is ${new Date()}
  `);
};

我的页面/build.js:

my pages/build.js:

const fs = require('fs');
fs.writeFile(
  'pages/api/built-time.js',
  `module.exports = '${new Date()}'`,
  (err) => {
    if (err) throw err;
    console.log('Build time file created successfully!');
  }
);

我的 package.json:

my package.json:

{
...
"scripts":{
    "vercel-build": "node ./pages/api/build.js", 
  }
}

推荐答案

最后我没有使用vercel-build".我只是在构建之前运行一个脚本:

In the end I didn't use "vercel-build". I just run a script before the build:

// package.json
{
"scripts": {
    "make-q": "node ./build.js",
    "build": "yarn run make-q && next build",
}

构建文件不能使用导入或调用打字稿文件(至少现在是这样):

The build file can't use import or call typescript files (at least for now):

// build.js
const slugify = require('./utils/slugify');
const fs = require('fs');
const qs = slugify('some string');

fs.writeFile(
  'questionsDB.js',
  `module.exports = ${JSON.stringify(qs, null, 2)}`,
  (err) => {
    if (err) throw err;
    console.log('file created successfully!');
  }
);

最后,在 pages/api/test.js 中:

Finally, inside the pages/api/test.js:

const db = require('../../db');
module.exports = (req, res) => {
  res.setHeader('content-type', 'text/plain');
  res.send(`
    working:
    ${db}
  `);
};

现在,如果我调用 url/api/test,我会得到基于构建的结果.

Now, if I call url/api/test I get the result based on the build.

我尝试失败的事情:

  • 不同的节点版本
  • 更新nextjs
  • 删除 yarn.lock 并重新构建

这篇关于一个“routes-manifest.json"找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆