Artur Carvalho
Artur Carvalho

Reputation: 7167

A "routes-manifest.json" couldn't be found

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

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

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

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()}
  `);
};

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!');
  }
);

my package.json:

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

Upvotes: 2

Views: 5460

Answers (1)

Artur Carvalho
Artur Carvalho

Reputation: 7167

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!');
  }
);

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

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

Things I tried that failed:

  • Different node version
  • Update nextjs
  • remove yarn.lock and build again

Upvotes: 0

Related Questions