请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

執行 npm run dev 後出現 404 (Not Found) 的訊息

老師您好,跟著影片打代碼執行 npm run dev 出現404的訊息,以下是我的 server.js 檔案,不太確定是什麼問題造成的,想請老師看看

錯誤訊息
图片描述

server.js

const Koa = require('koa')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
	const server = new Koa()

	server.use(async (ctx, next) => {
		await handle(ctx.req, ctx.res)
		ctx.respond = false
	})

	server.listen(3000, () => {
		console.log('koa server listening on 3000')
	})
})

package.json 檔

{
	"name": "nextjs-project",
	"version": "1.0.0",
	"description": "",
	"main": "index.js",
	"scripts": {
		"test": "echo \"Error: no test specified\" && exit 1",
		"dev": "node server.js",
		"buid": "next build",
		"start": "next start"
	},
	"repository": {
		"type": "git",
		"url": "git+https://github.com/elftvxq/nextjs-project.git"
	},
	"author": "",
	"license": "ISC",
	"bugs": {
		"url": "https://github.com/elftvxq/nextjs-project/issues"
	},
	"homepage": "https://github.com/elftvxq/nextjs-project#readme",
	"dependencies": {
		"koa": "^2.13.0",
		"next": "^10.0.4",
		"react": "^17.0.1",
		"react-dom": "^17.0.1"
	}
}

正在回答 回答被采纳积分+3

插入代码

1回答

Jokcy 2021-01-04 21:24:16

建议把nextjs退到8.x版本试一下

1 回复 有任何疑惑可以回复我~
  • 提问者 elftvxq #1
    可以執行了~ 感謝老師
    回复 有任何疑惑可以回复我~ 2021-01-04 22:37:06
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号