nodemon crash -- app crashed - 在启动之前等待文件更改

nodemon crash -- app crashed - waiting for file changes before startin

参考以下代码:

import express from 'express';

const app = express();
const port = process.env.PORT || 9000;

app.get('/', (req, res)=>res.status(200).send('hello world'));

app.listen(port, ()=>console.log(`Listening on localhost:${port}`));

当我 运行 和 nodemon server.js 出现这个错误

有什么我遗漏的吗?

您没有使用 CommonJS 模块导入系统。如果你想使用ES6模块系统,你必须设置Babbel。

现在要解决此问题,请使用 CommonJS 模块导入系统。

const express = require('express');

const app = express();
const port = process.env.PORT || 9000;

app.get('/', (req, res)=>res.status(200).send('hello world'));

app.listen(port, ()=>console.log(`Listening on localhost:${port}`));