我意识到这很可能是一个重复的问题。我是nodemon的新手,我正在尝试使用nodemon为Vue JS项目建立服务器。我试图用nodemon运行eslint并且无法弄清楚为什么我一直收到错误消息。如果我在--exec之后删除了npm,它会告诉我'''运行'我不承认,如果我删除了,我会得到' lint'不被认可等等。 我的package.json文件:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"eslint": "^4.16.0",
"nodemon": "^1.14.12"
}
}
我也在我的启动脚本中尝试了这段代码:
"scripts" : {
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./nodemodules/.bin/eslint **/*.js"
}
在哪里告诉我"。"不被视为内部外部命令。 我已将nodemon安装到我的服务器文件夹和项目目录以及全局。我也和eslint做过同样的事情。
答案 0 :(得分:7)
i had the same problem today. did some google stuff and found that this is not working anymore. so i tried this
"scripts": {
"prestart": "npm run lint ",
"start": "nodemon src/app.js ",
"lint": "./node_modules/.bin/eslint src/*.js"
},
when you npm start
node will run the pre-start script before the start script.Once a file being updated this pre-start wont run by the nodemon.So for that we have to call the nodemon events.So create a nodemon.json
on root folder and paste following.
{
"events": {
"restart": "npm run lint"
}
}
you can read more nodemon config options from here nodemon config .There are more nodemon events.you can read them from here event restart
PS:im very new to this. :)
You can use as follows. this dont need a nodemon config;
"scripts": {
"start": "node src/app.js",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon src/app.js --exec \"npm run lint --fix && node\"",
"lint": "eslint --fix **/*.js "
}
for run use npm run dev
it will run es lint + nodemon. this is for windows cmd command.if you are using bash terminal, remove \
in "dev"
;
"dev": "nodemon src/app.js --exec "npm run lint --fix && node""
答案 1 :(得分:2)
我遇到了同样的问题。
由于某些原因,您不能在npm脚本中使用简单的引号。
请改用转义的双引号。这应该起作用:
"start": "nodemon src/app.js --exec \"npm run lint && node\""