我按照https://nextjs.org/learn/basics/getting-started/setup的说明进行所有操作

我运行npm run dev

并显示错误

Div-Man@DivMan MINGW64 /f/nextjs/hello-next
$ npm run dev

> [email protected] 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! [email protected] dev: `next`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

> [email protected] 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! [email protected] start: `next start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

最佳答案

nextJS需要进入“页面”目录。

创建“页面”,然后在内部创建index.js。 (例如pages / index.js)

关于node.js - 找不到`pages`目录。 nextjs,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53203694/

10-11 04:06