首页 > 解决方案 > npm start 运行错误“var before = prev.prev || {}; TypeError:无法读取未定义的属性'prev'”

问题描述

目前我正在尝试使用节点运行一个非常基本的待办事项列表。设置好 package.json 和 server.js 后,我运行了 npm start run,但出现了一个奇怪的错误。

更新:这是基本代码和 .json 文件: 在此处输入图像描述

var express = require('express'),
app = express(),
port =process.env.PORT ||3000;

app.listen(端口);

console.log('todo list RESTful API server started on: ' + port);

这是错误: 在此处输入图像描述

这是完整的日志页面: 在此处输入图像描述

标签: javascriptnode.jsnpmnpm-start

解决方案


I ran into the same problem with nodemon when running my test scripts in a node.js api.

It seems the error is related to this issue with nanomatch, a package nodemon uses, a link to the issue: https://github.com/micromatch/nanomatch/issues/15.

I solved it with the following steps:

  1. Verify the version of nanomatch in node_modules/nanomatch/package.json if the version is 1.2.11 (I also had a similar issue with 1.2.9) you need to change its version.
  2. Run npm i nanomatch@1.2.13 (--save or --save-dev according to your situation)

After these steps nodemon worked for me. Hope that helps.


推荐阅读