我已经尝试了几次使用快速启动方法npx create-next-app
从头开始NextJS项目,并遵循教程示例https://nextjs.org/learn/excel/static-html-export/setup中概述的说明。我想创建一个静态HTML网站。
我将build
和export
作业添加到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: '/' }
};
}
};
构建运行正常,但是当我尝试运行导出时,出现以下错误:
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"
答案 0 :(得分:2)
我更改了module.exports
代码,但未能返回我创建的paths
对象。文件next.config.js
应该如下所示:
module.exports = {
exportPathMap: async function() {
const paths = {
'/': { page: '/' }
};
return paths; //<--this was missing previously
}
};