NEXT.JS -错误:导出在以下路径上遇到错误:/favicon. ico

kfgdxczn  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(104)

我试着next export
预呈现页面“/blogs/[post]"时发生错误。阅读更多:https://err.sh/next.js/prerender-error错误:页面/blogs/[post]错误:无法导出包含getServerSideProps的页面。查看更多信息此处:https://err.sh/next.js/gssp-export at Object.exportPage [as default](C:_PROJECT\bimeshow-master-27-02-1400\node_modules\next\dist\export\worker.js:15:254)info - undefined(33/33)Error:Export encountered errors on following paths:(C:_PROJECT\bimeshow-master-27-02-1400\node_modules\next\dist\export\index.js:24:1103)at processTicksAndRejections(internal/process/task_queues.js:93:5)
blogs/[post].js:

...
export const getServerSideProps = async ({params}) => {
    const postUrl = params.post;
    const res = await axios({
        method: 'post',
        url: `/blog/single2?seo_url=${encodeURI(postUrl)}`
    });

    return { 
        props: { 
            data:res!=undefined? res.data.data : []
        }
    }
  }

字符串
routes.js:

module.exports = () => {
    return {
      '/': { page: '/' },
      '/about-us': { page: '/about-us' },
      '/404': { page: '/404' },
      '/login': { page: '/login' },
      '/blogs':{ page : '/blogs'},
      '/blogs/[post]': {page: '/blogs/[post]'},
    }


server.js

const express = require('express');
const next = require('next');
const { parse } = require('url');

const DEV = process.env.ENVIRONMENT !== 'production';
const PORT = 4567;

const app = next({dir: '.', dev: DEV});
const handle = app.getRequestHandler();

const getRoutes = require('./routes');

const routes = getRoutes();
  app.prepare().then(() => {
    const server = express();
    server.get('*', (req, res) => {
      const parsedUrl = parse(req.url, true);
      const { pathname, query } = parsedUrl;
      const route = routes[pathname];
      if (route) {
        return app.render(req, res, route.page, route.query);
      }
      return handle(req, res);
  });

  server.listen(PORT, (err) => {
    if (err) throw err;
    console.log(`> READY FOR LIFOTFF http://localhost:${PORT}`);
  });
});

h43kikqp

h43kikqp1#

由于错误消息中的链接信息已经指出:getServerSideProps与下一个导出不兼容。您需要将其更改为getStaticProps。
https://nextjs.org/docs/messages/gssp-export
下面是getStaticProps的文档:
https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation

相关问题