最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to fix the 'no severless pages built' in nextjs deployment using vercel? - Stack Overflow

programmeradmin1浏览0评论

I' am trying to deploy my NextJs app. I have been getting the same 2 errors the past few days:

1: // and will just error later on
2: Error: No serverless pages were built. Learn More:
I have got no clue on how to fix both of them. I would appreciate it if anyone helped

This is my package.json file:

{
  "name": "my-dev-portfolio",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "next",
    "bulid": "next build",
    "start": "next start",
    "now-build": "next build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.1.1",
    "@fortawesome/free-brands-svg-icons": "^6.1.1",
    "@fortawesome/free-solid-svg-icons": "^6.1.1",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "next": "^12.2.0",
    "react-dom": "^18.2.0",
    "typewriter-effect": "^2.19.0"
  }
}

The next.config.json file:

module.exports = {
    target: "serverless"
}

now.json file:

{
    "version": 2,
    "builds": [{"src":"package.json", "use": "@now/next"}]
}

I' am trying to deploy my NextJs app. I have been getting the same 2 errors the past few days:

1: // and will just error later on
2: Error: No serverless pages were built. Learn More: https://err.sh/vercel/vercel/now-next-no-serverless-pages-built
I have got no clue on how to fix both of them. I would appreciate it if anyone helped

This is my package.json file:

{
  "name": "my-dev-portfolio",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "next",
    "bulid": "next build",
    "start": "next start",
    "now-build": "next build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.1.1",
    "@fortawesome/free-brands-svg-icons": "^6.1.1",
    "@fortawesome/free-solid-svg-icons": "^6.1.1",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "next": "^12.2.0",
    "react-dom": "^18.2.0",
    "typewriter-effect": "^2.19.0"
  }
}

The next.config.json file:

module.exports = {
    target: "serverless"
}

now.json file:

{
    "version": 2,
    "builds": [{"src":"package.json", "use": "@now/next"}]
}
Share Improve this question edited Jul 30, 2022 at 15:39 George Marwanqana asked Jul 30, 2022 at 15:31 George MarwanqanaGeorge Marwanqana 4191 gold badge7 silver badges22 bronze badges 3
  • 1 Any code that you can share? – paulogdm Commented Jul 30, 2022 at 15:34
  • I Just put it on @paulogdm – George Marwanqana Commented Jul 30, 2022 at 15:40
  • 1 You don't need the now.json nor target there. Remove those files and check your project's settings to see if Next.js is set as the framework. – paulogdm Commented Jul 31, 2022 at 14:10
Add a ment  | 

4 Answers 4

Reset to default 8

Try this if you're working with newer version of node

Navigate to settings of your project in Vercel dashboard

https://vercel./[username]/[project]/settings

Follow this process to fix:

  1. Scroll down to Node.js Version of Search for Node.js Version on the page
  2. Select a newer version, probably 16x or 18x and not 14x
  3. Click the 'SAVE' button
  4. Navigate back to Deployments https://vercel./[username]/[project]/deployments
  5. Click the hamburger menu (three dots) in your most recent mit
  6. Then click the 'REDEPLOY' button and make sure not to select the cache option

App should build successfully now

Ensure to replace [username] and [project] with your respective vercel username and vercel project id

For now.json: you are using a very old method. Vercel can now detect your framework. Check the announcement in the blog: Zero Config Deployments .

For next.config.js where you are using target: serverless, that is also not needed at all. Just remove it if you are deploying to Vercel. For those curious, check https://nextjs/docs/advanced-features/output-file-tracing for more information on a better solution that replaced target.

You dont need now.json file. Delete it and try deployment again

For me it was caused by sentry. Locally the app ran fine, but when built it failed with this error. When I removed withSentryConfig from the last line modyifing it from:

module.exports = withSentryConfig(nextConfig, SentryWebpackPluginOptions)     

to

module.exports = nextConfig

It built again on vercel.

I suspect it's caused by a bug in @sentry/nextjs where it does not pass pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'] correctly to next.js on build.

发布评论

评论列表(0)

  1. 暂无评论