目录
- 出错现象
- 出错原因
- 解决方案
出错现象
npm init -y
初始化之后,安装项目npm i prettier -D
报错
PS E:\professer\StyleLint\Prettier> npm i prettier -D
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "prettier" under a package
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR! <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\AppData\Roaming\npm-cache\_logs\2020-11-02T13_49_21_069Z-debug.log
出错原因
两次都出现这个错误,其实和prettier
包没有关系,是因为package.json
的项目名称和安装的依赖同名导致
{
"name": "prettier",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "MIT",
"devDependencies": {},
"keywords": []
}
解决方案
修改package.json
中的name
为prettier-sample
,总之不要和安装的包名相同即可。
网友评论