npm でライブラリをアンインストールする方法


npm でインストールしたライブラリをアンインストールする方法をメモします。

書き方

npm uninstall パッケージ名

package.jsonのdevDependenciesが下記だったとする

package.json
{
  "name": "npm uninstall",
  "version": "0.1.0",
  "private": true,
  "scripts": {
  },
  "dependencies": {
  },
  "devDependencies": {
    "@types/node": "^14.14.14",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "prettier": "2.2.1",
    "tslint-config-prettier": "^1.18.0",
    "tslint-plugin-prettier": "^2.3.0",
    "tslint-react": "^5.0.0",
    "typescript": "^4.1.3"
  }
}

「prettier」をアンインストールしたい場合は下記のように書く

npm uninstall prettier

npm install したときは、--save-devとかが必要だったけど、uninstallするときはいらないみたい。(2020/12/28時点)