Node.js v20.12.2 [nodemon] 应用程序崩溃 - 启动前等待文件更改

问题描述 投票:0回答:1

我正在关注 freecodecamp 上 YouTube 上标题为“MERN Stack 教程 - 书店项目”的教程 我正在尝试在端口 5555 上运行它 我仍处于项目开始阶段,只是想检查服务器是否正在运行 这是链接https://www.youtube.com/watch?v=-42K44A1oMA 问题是我在运行命令“npm run dev”后遇到问题,因为我收到此错误:Node.js v20.12.2 [nodemon] 应用程序崩溃 - 启动前等待文件更改...截图供参考error screenshot

package.json 代码片段

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.19.2",
    "nodemon": "^3.1.0"
  }
}

index.js 代码片段

import express from "express";
import { PORT } from "./config";

const app = express();

app.listen(PORT, () => {
    console.log("App is listening to port: ${PORT}");
});

config.js 代码片段

import express from "express";
import { PORT } from "./config";

const app = express();

app.listen(PORT, () => {
    console.log("App is listening to port: ${PORT}");
});

我已经尝试了互联网上各个网站的很多解决方案,但仍然面临问题,有人可以帮助我解决这个问题吗? 我尝试从任务管理器中结束nodejs,但它不起作用 更新了nodejs没用 删除了缓存但没有用 卸载了又安装了还是不行

我使用的是Windows

reactjs node.js express
1个回答
0
投票

您的导入错误。您应该在index.js中导入

./config.js

import { PORT } from "./config.js";

另请注意,您的代码片段是相同的。

© www.soinside.com 2019 - 2024. All rights reserved.