'npm' is not recognized as an internal or external command, a operable program or a batch file

Asked

Viewed 10,099 times

0

Good evening! I have this problem. I have tried some things I found on the net but nothing has worked so far. npm is installed ([email protected] C: Program Files nodejs node_modules npm) and PATH (C: Program Files nodejs). Please help me:

$ npm run dev

> @ dev C:\xampp\htdocs\lsapp
> npm run development

'npm' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
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.

Below is the error log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dev' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle @~predev: @
6 info lifecycle @~dev: @
7 verbose lifecycle @~dev: unsafe-perm in lifecycle true
8 verbose lifecycle @~dev: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\xampp\htdocs\lsapp\node_modules\.bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Jeferson\bin;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapat;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\MySQ";C:\Program Files (x86)\Common Files\Oracle\Java\javapat;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Java\jdk1.8.0_202\bin;.;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;C:\Users\Jeferson\AppData\Local\Microsoft\WindowsApps;C:\Users\Jeferson\AppData\Roaming\Composer\vendor\bin;C:\Users\Jeferson\AppData\Roaming\npm;C:\Program Files\nodejs
9 verbose lifecycle @~dev: CWD: C:\xampp\htdocs\lsapp
10 silly lifecycle @~dev: Args: [ '/d /s /c', 'npm run development' ]
11 silly lifecycle @~dev: Returned: code: 1  signal: null
12 info lifecycle @~dev: Failed to exec dev script
13 verbose stack Error: @ dev: `npm run development`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:197:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:197:13)
13 verbose stack     at maybeClose (internal/child_process.js:984:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid @
15 verbose cwd C:\xampp\htdocs\lsapp
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v11.10.0
19 verbose npm  v6.7.0
20 error code ELIFECYCLE
21 error errno 1
22 error @ dev: `npm run development`
22 error Exit status 1
23 error Failed at the @ dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
  • 1

    Did you install NPM? If so, make sure to add to Windows PATH?

  • what are you doing, typing npm in the terminal?

  • Hello! I changed the post with the information. Thank you for your attention!

  • The error in question is somewhat incoherent, since it is first said that npm is not recognized as a command, but then shows some logs NPM error message. Are you sure that’s the correct error message you get?

  • I agree with you that it is strange, but this is the return I have. If I just type 'npm' it shows me the options. If I type 'npm -v' it gives me the return '6.7.0'. If I type 'npm run' it shows me the options, but finally if I type 'npm run dev' it returns me the error above. I will edit the question and add the error log to see if it helps. Thanks for your attention!

  • I think you’re calling nmp of bash or of powershell. Flame of the prompt of DOS or else enter (both bash and powershell) with the command CMD.exe opening a DOS prompt, do your job with nmp and use exit to get out of DOS.

  • 1

    @Augustovasques Very grateful! That way it works!!! I just don’t understand yet why the bash of VS Code doesn’t work :(... But at least now I can continue my studies! Thanks!

  • @Jefersonferreira. Because both the bash and the powershell do not give conventional support to environment variables. The powershell only supports, these variables via active directory and bash in turn uses dynamics POSIX that ignores the environment variables. So when you call the cmd.exe you are actually invoking the DOS environment that provides some system protocols among which are included these variables necessary to execute the nmp.

  • Got it. Thanks for the help! Hug!

Show 4 more comments

2 answers

3

To resolve the issue, run on terminal:

npm install --global cross-env

Run the npm run dev

Source: schoolofnet

Another source: Soen

  • 1

    It is in Windows environment. Does not exist sudo for windows.

  • 1

    Okay, I changed it!

  • 1

    There is even sudo for Windows. But it’s pretty rudimentary and only works if you install support for POSIX server only to add some linux core tools in windows.

  • Unfortunately it didn’t work out here :(

  • Which error appeared when you executed this command?

  • https://npm.community/t/problem-installing-depcheck-with-npm-6-7-0/4913/3 mentioned here are some bugs

  • When I spin the install it gives update of 1 package. Then running the dev makes the same mistake.

  • How strange, try to use these 2 versōes, from a downgrade in the Node: 10.14.1 and npm: 6.8.0

  • It didn’t work either. It only works on cmd from Windows ( @Augustovasques tip).

  • I will put in response format because I saw in Meta a publication warning about do not put answers in comments.

Show 5 more comments

0

What is causing the error?

I believe you’re calling nmp of bash or of powershell.

Why this error occurs?

Because both the bash like the powershell do not give conventional support(DOS) environment variables. powershell only supports these variables via active directory by syntax:

dir env: $Env:variablename

or

gci env: $Env:variablename

bash in turn uses POSIX dynamics that ignore the concept of windows environment variables and uses its own variable model. General, user and shell variables. Where to access them the syntax is used:

env [OPÇÕES]... [-] [NOME=VALOR]... [COMANDO [ARG]...]

So when you call 'cmd.exe' you are actually invoking the environment 'DOS' which provides some system protocols among which are included these variables necessary to run 'nmp'.

Solution.

Invoke the nmp of the prompt of DOS or else enter (both in bash as to the powershell) with the command CMD.exe to open an inline prompt DOS, do your job with nmp and use Exit to exit the DOS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.