reactjs - 将 React 与 Next.js 演示一起使用不起作用
问题描述
我的 Package.js
{
"name": "nextjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build",
"prod_start": "NODE_ENV=production node server.js",
"start": "next start"
},
"author": "",
"license": "ISC",
"dependencies": {
"next": "^9.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}
下面是错误日志。
Error: Could not find a valid build in the 'xxx/nextjs/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (xxx/node_modules/next-server/dist/server/next-server.js:425:23)
at new Server (xxx/node_modules/next-server/dist/server/next-server.js:43:29)
at module.exports (xxx/node_modules/next-server/index.js:4:10)
at module.exports.options (xxx/node_modules/next/dist/server/next.js:2:161)
at start (xxx/node_modules/next/dist/server/lib/start-server.js:1:385)
at nextStart (xxx/node_modules/next/dist/cli/next-start.js:22:125)
at commands.(anonymous function).then.exec (xxx/node_modules/next/dist/bin/next:29:346)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:695:11)
运行 npm start 时,在 node_modules/next-server/dist/server/next-server.js 内显示错误
解决方案
先跑npm run build
。当您运行时npm run start
,它会尝试启动本地服务器,以便您可以在本地运行您的应用程序。但是,如果您刚刚安装它并且尚未构建您的应用程序(如错误所示),则您的本地服务器没有任何可提供的服务。
如果您想在开发时在本地运行它(即实时重新加载),请使用npm run dev
.
推荐阅读
- python - SageMaker 脚本模式 + 管道模式
- excel - 不引用excel表上的列
- autodesk-forge - 为什么文本标记大小因缩放而异?
- sql - 使用 CalendarTable SQL Server 2008 计算 NETWORKDAYS
- flask - Psycopg2 和 Flask - 将连接绑定到 before_request 和 teardown_appcontext
- zendesk - 页面重新加载后如何触发 zendesk Web 小部件?
- android - 表 users_data 没有名为的列
- sql - 有没有更好的方法来拆分简单更新的工作?
- java - 删除 ArrayList 中大于 x 的数字
- reactjs - 模拟表单提交时无法读取属性“值”