0

I am just checking the npm version using npm --v command. But whenever I run any npm command I get the following error

'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
operable program or batch file.

I tried installing react js in Laravel project for that I needed to run following command

When I just run the npm command, following error appears

'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
operable program or batch file.

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    C:\Users\Dell\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.13.7 C:\Program Files\nodejs\node_modules\npm

    npm run dev
But this command too throws error along with the above error

    'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
    operable program or batch file.

    > @ dev C:\xampp\htdocs\laravel-react\CRUD
    > npm run development

    npm ERR! code ELIFECYCLE
    npm ERR! syscall spawn C:\Windows\system32\cmd.exe;C:\xampp\php;
    npm ERR! file C:\Windows\system32\cmd.exe;C:\xampp\php;
    npm ERR! path C:\Windows\system32\cmd.exe;C:\xampp\php;
    npm ERR! errno -4058
    npm ERR! @ dev: `npm run development`
    npm ERR! spawn C:\Windows\system32\cmd.exe;C:\xampp\php; ENOENT
    npm ERR!
    npm ERR! Failed at the @ dev script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\Dell\AppData\Roaming\npm-cache\_logs\2020-03-25T14_19_49_350Z-debug.log



I have already set up my environment variables and it seems correct to me.

**User Variable**

    C:\Users\Dell\AppData\Roaming\npm

**System Variable**

    C:\Program Files\nodejs\

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@babel/preset-react": "^7.0.0",
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "cross-env": "^7.0",
        "jquery": "^3.2",
        "laravel-mix": "^5.0.1",
        "lodash": "^4.17.13",
        "popper.js": "^1.12",
        "react": "^16.2.0",
        "react-dom": "^16.2.0",
        "resolve-url-loader": "^3.1.0",
        "sass": "^1.15.2",
        "sass-loader": "^8.0.0"
    }
}

I also followed some answers on Stack Overflow and tried completely uninstalling and reinstalling the Node js but it doesn't work.

Even this https://stackoverflow.com/a/49505612/4494813 didn't work for me.

fahad shaikh
  • 359
  • 5
  • 15
  • If npm --v is not working. Try this solution: https://stackoverflow.com/questions/20992723/npm-is-not-recognized-as-internal-or-external-command-operable-program-or-bat – Shubham Sharma Mar 25 '20 at 14:43
  • still not working, I have updated the question – fahad shaikh Mar 25 '20 at 17:11
  • Can you share package.json as well? – Shubham Sharma Mar 26 '20 at 09:26
  • I have updated the question with package.json file – fahad shaikh Mar 26 '20 at 17:38
  • There are some missing packages in your Package.json like Webpack. Can you validate it? Also, try to run npm --v if it works then try to run npm run development in your project directory. I hope before running npm run development you have installed all the dependencies using npm install – Shubham Sharma Mar 27 '20 at 06:00
  • I have `webpack.mix.js` file in my project. `npm --v` outputs the npm version along with error mentioned in the question but `npm run dev` doesn't work and yes I ran `npm installed` before `npm run dev` command – fahad shaikh Mar 29 '20 at 15:01

1 Answers1

0

Check your node version first

Clean your cache

And reinstall node modules again

rm -rf node_modules

npm cache clean --force

npm i

npm run dev
rojjot
  • 1