【问题标题】:The dev server never responds when starting an empty project based on NextJs documentation根据 NextJs 文档启动空项目时,开发服务器从不响应
【发布时间】:2019-11-19 12:37:33
【问题描述】:

基于NextJs framework documentation,我按照一些设置步骤运行了一个空项目:

mkdir hello-next
cd hello-next
npm init -y
npm install --save react react-dom next
mkdir pages

然后我将这 3 行添加到我的 package.json 文件中:

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

所以现在一切都应该准备好让我的应用程序运行,执行这个命令行:

npm run dev

但我总是在http://localhost:3000 上陷入无休止的加载循环

在我的控制台输出上:

[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:3000 ...
[ ready ] compiled successfully (ready on http://localhost:3000)

【问题讨论】:

    标签: javascript reactjs next.js


    【解决方案1】:

    你是对的,它不像教程建议的那样工作。我在 Next Github 存储库中打开了an issue,该问题现已解决,9.0.1 版本中应该会提供修复。

    同时,您可以通过在pages 目录中创建一个名为index.jsindex.jsx 的文件并重新启动服务器来添加一个简单的页面。

    // pages/index.js
    export default () => 'Super simple page';
    

    然后,导航到http://localhost:3000 应该会显示这个页面,而任何其他路径应该会显示默认的 Next 的 404 错误页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多