【问题标题】:Error running npm test command in windows with git bash [duplicate]使用 git bash 在 Windows 中运行 npm test 命令时出错 [重复]
【发布时间】:2020-08-16 20:12:34
【问题描述】:

我在 package.json 中有以下 test 命令

"test": "rm -rf ./junit.xml && ./node_modules/.bin/react-scripts test --verbose --env=jsdom --testResultsProcessor ./node_modules/jest-junit"

现在我正在使用windows 笔记本电脑,并在git bash 工具的帮助下运行npm test 命令。

我遇到以下错误:

> rm -rf ./junit.xml && ./node_modules/.bin/react-scripts test --verbose --env=jsdom --testResultsProcessor ./node_modules/jest-junit

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed.  See above for more details.

我试过这个帖子 - How to fix '.' is not an internal or external command error

并使用以下选项:

"test": "rm -rf junit.xml && node_modules/.bin/react-scripts test --verbose --env=jsdom --testResultsProcessor node_modules/jest-junit"

我得到错误:

rm -rf junit.xml && node_modules/.bin/react-scripts test --verbose --env=jsdom --testResultsProcessor node_modules/jest-junit

'node_modules' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed.  See above for more details.

还有这个:

"test": "rm -rf .\junit.xml && .\node_modules\.bin\react-scripts test --verbose --env=jsdom --testResultsProcessor .\node_modules\jest-junit"

我得到以下错误:

npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\name\AppData\Roaming\npm-cache\_logs\2020-05-02T10_15_55_006Z-debug.log

正确的使用方法是什么?

【问题讨论】:

  • 例如:"test": "rm -rf \"./junit.xml\" && \"./node_modules/.bin/react-scripts\" test --verbose --env=jsdom --testResultsProcessor \"./node_modules/jest-junit\""

标签: node.js reactjs npm package.json


【解决方案1】:

你应该像这样转义反斜杠

"test": "rm -rf .\\junit.xml && .\\node_modules\\.bin\\react-scripts test --verbose --env=jsdom --testResultsProcessor .\\node_modules\\jest-junit"

【讨论】:

    猜你喜欢
    • 2020-05-31
    • 2019-10-03
    • 2014-08-01
    • 2017-07-03
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    相关资源
    最近更新 更多