nodemon ''mocha' is not recognized as an internal or external command, operable program or batch file

前端 未结 8 682
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 06:25

Running a test for a nodejs project on windows 10 with the line in package.json as:

\"test\": \"nodemon --exec \'mocha -R min\'\"

I get:

相关标签:
8条回答
  • 2021-01-04 06:49

    Inside the package.json, you need to add a new script right after the "test" script. We can create a custom script and named it as "test-watch" and the value of the "test-watch"is "nodemon --exec \"npm test\""(i.e "test-watch": "nodemon --exec \"npm test\"") After this step we can use npm run test-watch command in terminal.

    0 讨论(0)
  • 2021-01-04 06:50

    An alternative approach is to add the mocha path to the environment variables then restart the bash On your editor, navigate to the bin folder of mocha and add both paths to your system environments. All script options that have been illustrated work with this approach

    "scripts": {
        "test": "nodemon --exec \"mocha -R min\""
    }
    

    or

    "scripts": {
        "test": "nodemon --exec 'mocha -R min'"
    }
    

    or

    "scripts": {
        "test": "nodemon --exec mocha -R min"
     }
    

    in the package.json file are correct dependencies definition

    I hope this helps fix the issue.

    0 讨论(0)
  • 2021-01-04 06:51

    install mocha globally then it will work

    npm install -g mocha --save-dev

    0 讨论(0)
  • 2021-01-04 06:53

    Also, check your NODE_ENV=development if you are on Windows and are using git-bash. For some reason, it defaults to production.

    $ echo $NODE_ENV
    

    With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in "devDependencies"

    You can verify this by checking your node_modules/ folder and see if mocha was installed. If not:

    $ npm install --only=dev
    

    also:

    $ NODE_ENV=development
    $ npm i -D mocha
    

    would do the trick.

    0 讨论(0)
  • 2021-01-04 06:53
    "test": "mocha **/*.test.js",
    "test-watch": "nodemon --exec \"npm test\""
    

    For Run

    npm run test-watch
    
    0 讨论(0)
  • 2021-01-04 06:58

    That worked fine with the line:

    "test": "nodemon --exec \"mocha -R min\""
    

    in package.json

    0 讨论(0)
提交回复
热议问题