【问题标题】:A "routes-manifest.json" couldn't be found找不到“routes-manifest.json”
【发布时间】:2023-03-03 08:48:23
【问题描述】:

我正在关注this tutorial,以便在 Vercel 构建期间生成一个静态文件。我试过移动文件,但它总是显示如下日志:

23:41:48.432 $ node ./pages/api/build.js 23:41:48.493 Build time file created successfully! 23:41:48.495 Done in 0.09s. 23:41:48.507 Error: A "routes-manifest.json" couldn't be found. This is normally caused by a misconfiguration in your project.

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

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

我的页面/api/index.js 文件:

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:

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:

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

【问题讨论】:

    标签: next.js vercel


    【解决方案1】:

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

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

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

    // 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 里面:

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

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

    我尝试过的事情失败了:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-09
      • 2020-04-26
      • 2021-04-27
      • 2019-05-10
      • 2018-10-19
      • 2023-04-07
      相关资源
      最近更新 更多