gpt4 book ai didi

next.js - 导出静态 NextJS 应用 `TypeError: Cannot read property '/40 4' of undefined`

转载 作者:行者123 更新时间:2023-12-04 01:38:40 26 4
gpt4 key购买 nike

我已经尝试了几次使用快速启动方法从头开始 NextJS 项目 npx create-next-app并遵循教程示例 https://nextjs.org/learn/excel/static-html-export/setup 中概述的结构.我想创建一个静态 HTML 站点。

我添加了 buildexport工作到scripts标签在 package.json :

  "scripts": {
"dev": "next dev",
"build": "next build",
"export": "next export",
"start": "next start"
},

并创建一个 next.config.js示例中的文件:
const fetch = require('isomorphic-unfetch');

module.exports = {
exportPathMap: async function() {
const paths = {
'/': { page: '/' }
};
}
};

构建运行良好,但是当我尝试运行 export 时出现以下错误:
TypeError: Cannot read property '/404' of undefined
at _default (~/Workspace/BlogNextJS/my-blog/node_modules/next/dist/export/index.js:10:202)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-blog@0.1.0 export: `next export`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-blog@0.1.0 export script.

当我使用教程中的示例项目时不会发生这种情况 ( https://github.com/zeit/next-learn-demo.git )

任何人都可以告诉我可能会发生什么或指示要查看的内容吗?

日志中的更多信息如下所示,但我不太了解它的含义:
6 info lifecycle my-blog@0.1.0~export: my-blog@0.1.0
7 verbose lifecycle my-blog@0.1.0~export: unsafe-perm in lifecycle true
8 verbose lifecycle my-blog@0.1.0~export: PATH: /home/klol/.nvm/versions/node/v12.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/klol/Workspace/BlogNextJS/my-blog/node_modules/.bin:/home/klol/.nvm/versions/node/v12.12.0/bin:/home/klol/anaconda3/bin:/home/klol/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle my-blog@0.1.0~export: CWD: /home/klol/Workspace/BlogNextJS/my-blog
10 silly lifecycle my-blog@0.1.0~export: Args: [ '-c', 'next export' ]
11 silly lifecycle my-blog@0.1.0~export: Returned: code: 1 signal: null
12 info lifecycle my-blog@0.1.0~export: Failed to exec export script
13 verbose stack Error: my-blog@0.1.0 export: `next export`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/home/klol/.nvm/versions/node/v12.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:210:5)
13 verbose stack at ChildProcess.<anonymous> (/home/klol/.nvm/versions/node/v12.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:210:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid my-blog@0.1.0
15 verbose cwd /home/klol/Workspace/BlogNextJS/my-blog
16 verbose Linux 5.0.0-31-generic
17 verbose argv "/home/klol/.nvm/versions/node/v12.12.0/bin/node" "/home/klol/.nvm/versions/node/v12.12.0/bin/npm" "run" "export"

最佳答案

我已经改变了 module.exports代码并未能返回 paths我创建的对象。文件 next.config.js应该是这样的:

module.exports = {
exportPathMap: async function() {
const paths = {
'/': { page: '/' }
};
return paths; //<--this was missing previously
}
};

关于next.js - 导出静态 NextJS 应用 `TypeError: Cannot read property '/40 4' of undefined`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58483247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com