【问题标题】:npm run: command not foundnpm 运行:找不到命令
【发布时间】:2023-02-14 23:22:51
【问题描述】:

当我尝试运行 npm run devnpm run build 时,出现以下错误:

npm run dev

> dev
> next

/usr/bin/bash: D:Tempdev-1656515078305.sh: command not found

这是我现在的package.json

{
  "private": true,
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "type-check": "tsc"
  },
  "dependencies": {
    "bootstrap": "^5.1.3",
    "marked": "^4.0.17",
    "next": "latest",
    "nodemailer": "^6.7.5",
    "react": "^18.1.0",
    "react-bootstrap": "^2.4.0",
    "react-dom": "^18.1.0",
    "react-icons": "^4.4.0"
  },
  "devDependencies": {
    "@fullhuman/postcss-purgecss": "^4.1.3",
    "@types/node": "^17.0.35",
    "@types/react": "^18.0.9",
    "@types/react-dom": "^18.0.4",
    "@typescript-eslint/eslint-plugin": "^5.30.0",
    "@typescript-eslint/parser": "^5.30.0",
    "eslint": "^8.18.0",
    "eslint-config-standard": "^17.0.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-n": "^15.2.3",
    "eslint-plugin-promise": "^6.0.0",
    "eslint-plugin-react": "^7.30.1",
    "eslint-plugin-react-hooks": "^4.6.0",
    "postcss-preset-env": "^7.6.0",
    "sass": "^1.53.0",
    "tailwindcss": "^3.0.24",
    "typescript": "4.6"
  }
}

我完全不知道为什么会出现此错误。

安装 NodeJS 和 NPM:

node -v
v16.14.2

npm -v
8.13.1

【问题讨论】:

  • 试试npx next看看会发生什么。还有ls node_modules/.bin
  • 有趣的是,错误消息指示“D:”(通常是 Windows 驱动器标识符)和 /usr/bin/bash(非 Windows,除非它是 WSL)。
  • npx next 运行没有任何错误。这是ls node_modules/.bin的结果:toptal.com/developers/hastebin/zuporoniti.yaml
  • cmd和PowerShell我都试过了,两者都报错。
  • 你需要做npm install吗?您是否偶然在全球范围内安装了nextnpm uninstall next -g 删除它,然后再次尝试npm run dev

标签: node.js npm next.js npm-run


【解决方案1】:

从另一个调用一个运行脚本时,我遇到了这个问题。使用 npm-run-all 和 run-s 启动命令修复了我在某些情况下的问题。我怀疑 npm 正在根据“平台”对 shell 和路径分隔符做出一些假设,或者没有正确地反省正在运行的 shell。

【讨论】:

    猜你喜欢
    • 2017-10-25
    • 1970-01-01
    • 2017-03-25
    • 2016-02-08
    • 2021-09-11
    • 1970-01-01
    • 2017-03-20
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多