我按照https://nextjs.org/learn/basics/getting-started/setup
的说明进行所有操作我运行npm run dev
并显示错误
Div-Man@DivMan MINGW64 /f/nextjs/hello-next
$ npm run dev
> hello-next@1.0.0 dev F:\nextjs\hello-next
> next
> Couldn't find a `pages` directory. Please create one under the project root
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-next@1.0.0 dev: `next`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-next@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Div-Man\AppData\Roaming\npm-cache\_logs\2018-11-08T07_58_57_773Z-debug.log
$ node -v
v10.6.0
$ npm -v
6.1.0
Windows 8.1
package.json
{
"name": "hello-next",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "next",
"build": "next build",
"start": "next start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"next": "^7.0.2",
"react": "^16.6.1",
"react-dom": "^16.6.1"
}
}
npm start
> hello-next@1.0.0 start F:\nextjs\hello-next
> next start
Error: Could not find a valid build in the 'F:\nextjs\hello-next\.next' director y! Try building your app with 'next build' before starting the server.
at Server.readBuildId (F:\nextjs\hello-next\node_modules\next\dist\server\ne xt-server.js:753:15)
at new Server (F:\nextjs\hello-next\node_modules\next\dist\server\next-serve r.js:80:25)
at module.exports (F:\nextjs\hello-next\node_modules\next\dist\server\next.j s:6:10)
at _callee$ (F:\nextjs\hello-next\node_modules\next\dist\server\lib\start-se rver.js:33:37)
at tryCatch (F:\nextjs\hello-next\node_modules\regenerator-runtime\runtime.j s:62:40)
at Generator.invoke [as _invoke] (F:\nextjs\hello-next\node_modules\regenera tor-runtime\runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (F:\nextjs\hello-next\ node_modules\regenerator-runtime\runtime.js:114:21)
at asyncGeneratorStep (F:\nextjs\hello-next\node_modules\@babel\runtime-core js2\helpers\asyncToGenerator.js:5:24)
at _next (F:\nextjs\hello-next\node_modules\@babel\runtime-corejs2\helpers\a syncToGenerator.js:27:9)
at F:\nextjs\hello-next\node_modules\@babel\runtime-corejs2\helpers\asyncToG enerator.js:34:7
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-next@1.0.0 start: `next start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-next@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Div-Man\AppData\Roaming\npm-cache\_logs\2018-11-08T08_25_2 3_194Z-debug.log
答案 0 :(得分:1)
nextJS需要到“页面”目录。
制作“页面”,然后在其中创建index.js。 (ex.pages / index.js)