Using the Next.js static site generator, I created a simple static site that I now want to deploy on Vercel. However, I keep encountering an error during the build process. While I have successfully deployed this site on other static hosting platforms before, I am eager to give Vercel a try.
The nextjs documentation states that my app requires zero configuration:
We strongly recommend using Vercel even if your Next.js app is fully static. Vercel is optimized to make static Next.js apps blazingly fast. next export works with Zero Config deployments on Vercel.
Below you can find my package.json file and the deployment scripts that run npm export
, which triggers next build && next export
to generate the out/
directory as per the docs:
next build && next export
{
"name": "new-barber-shop",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build && next export",
"export": "next export",
"start": "next start"
},
"author": "",
"license": "ISC",
"dependencies": {
"@zeit/next-css": "^1.0.1",
"google-maps-react": "^2.0.2",
"next": "^9.1.2",
"react": "^16.11.0",
"react-bootstrap": "^1.0.0-beta.14",
"react-dom": "^16.11.0",
"semantic-ui-react": "^0.88.1"
}
}
Here is a snippet from the Vercel deployment build logs showing the encountered error:
22:42:26.610
Compiled successfully.
...
Error: Cannot export when target is not server. https://err.sh/zeit/next.js/next-export-serverless
22:42:27.445
at _default (/vercel/path0/node_modules/next/dist/export/index.js:1:2956)
...
Although the compilation was successful, it seems to fail at the export stage. Any suggestions on how to tackle this issue would be greatly appreciated.
Additionally, here is my next.config.js configuration:
module.exports = {
target: 'serverless',
exportPathMap: function() {
return {
'/': { page: '/' }
};
}
};
Error log generated when executing npm run build
locally in the project (mirroring the error output experienced during deployment on Vercel):
$ npm run build
> [email protected] build F:\Austin\web-apps\new-barber-shop
> next build && next export
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
Creating an optimized production build
Compiled successfully.
Automatically optimizing pages
...
Error: Cannot export when target is not server. https://err.sh/zeit/next.js/next-export-serverless
...