Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM not recognized as an internal or external command #2642

Closed
lukanp opened this issue Apr 20, 2020 · 18 comments
Closed

NPM not recognized as an internal or external command #2642

lukanp opened this issue Apr 20, 2020 · 18 comments

Comments

@lukanp
Copy link

lukanp commented Apr 20, 2020

I’ve installed latest version of NodeJS and I'm trying to install Angular CLI , but...
When i try to use NPM commands i always get this message:
'CALL “C:\Program Files\nodejs\node_modules \npm\bin\npm-cli.js” prefix -g' is not recognized as an internal or external command

and then command is executed.Here's an image
1

and when I try to instal Angular cli with "npm install -g @angular/cli" this happens:
2

and Angular's not working
3

PS: here's my Environment Variables
USER:
user

SYSTEM:
system
I don't know what could be a problem. Please help me...
Thank you.

@lukanp
Copy link
Author

lukanp commented Apr 20, 2020

@benoitcornette Hey, I saw your post about same problem (https://npm.community/t/npm-v-returns-error-message-perfix-g-is-not-recognized-as-an-internal-or-external-command/4820 ). I wonder if you had fixed it. I would appreciate you help very much. Thank you.

@mscdex
Copy link

mscdex commented Apr 20, 2020

How did you install node?

@DerekNonGeneric
Copy link

This confirms my suspicions in the footnotes of https://github.com/nodejs/modules/issues/472#issuecomment-615950402.

image

/cc @nodejs/modules-active-members as I was also experiencing this and discussion has begun about error messages in nodejs/node#32052

My questions is what team is responsible for module specifiers being fed to the node CLI as arguments? Specifically Windows absolute root paths and the associated translation to absolute file URL paths existing in context.url of the resolve hook?

@DerekNonGeneric
Copy link

I would very highly value the opinion of @weswigham on this seeing as how TypeScript has already done all this work for us.

@DerekNonGeneric
Copy link

Maybe @nodejs/tsc would know as I haven't a clue about the various compatibility expectations here.

@weswigham
Copy link

Our path normalization code, as far as the string representation is concerned:

  • Replaces all \ with /
  • Reduces or eliminates all . or .. components to a minimal set
  • Preserves the trailing slash, if any

That's all.

We do not make a URL/Path distinction in our codebase - a Path may implicitly be a URL. To whit, in many places where we want to attempt to do local disk lookups, we call an isRootedDiskPath helper to check if a path is a / or c: (or similar) absolute path. The function getEncodedRootLength in path.ts is what performs the local path vs URL disambiguation for us. Do note, in addition to traditional POSIX paths, DOS paths, and URLs, it also disambiguates windows UNC paths. We have many helpers that answer questions about a path (is it absolute? is it rooted? is it local? what is the non-root part?) based on that disambiguation.

@benoitcornette
Copy link

@lukanp I just reinstalled my virtual machine completely and after that, everything worked perfectly.

@Hakerh400
Copy link

Related issues:

#1019
#1981
#2054
#2266
#2445

@mcollina
Copy link
Member

I don't understand this issue. It seems this issue should be in help, but I might be wrong. Is there anything that we can do to prevent this from happening?


@DerekNonGeneric I do not understand the question to the tsc.

@mscdex
Copy link

mscdex commented Apr 21, 2020

This seems like two separate issues to me?

@bzoz
Copy link

bzoz commented Apr 21, 2020

@lukanp, from your system variables:
image
Are you running antivirus software? Can you try uninstalling it and reinstalling Node?

@Hakerh400
Copy link

@lukanp Looking at your environment variables, I think the problem is related to your ComSpec having semicolon at the end. I can reproduce both of your issues if I add semicolon. Try to remove the semicolon, then start a new command prompt and try to run NPM again.

@DerekNonGeneric
Copy link

DerekNonGeneric commented Apr 22, 2020

/to @mcollina

@DerekNonGeneric I do not understand the question to the tsc.

Thanks for your reply! There was no question. :)


I don't understand this issue. [...]

There are problems on a few layers here. Judging by the title of the issue, the main concern seems to have been at the intersection of label:windows label:cli label:module.


Here's the full-text output of the error from my image (similar to OP's 3rd image):

C:\Users\Administrator>node /foo.mjs
internal/modules/cjs/loader.js:1029
  throw new ERR_REQUIRE_ESM(filename);
  ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\foo.mjs
�[90m    at Object.Module._extensions..mjs (internal/modules/cjs/loader.js:1029:9)�[39m
�[90m    at Module.load (internal/modules/cjs/loader.js:815:32)�[39m
�[90m    at Function.Module._load (internal/modules/cjs/loader.js:727:14)�[39m
�[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)�[39m
�[90m    at internal/main/run_main_module.js:17:11�[39m {
  code: �[32m'ERR_REQUIRE_ESM'�[39m
}

Those escape sequences (�[90m and �[39m) are probably the most interesting part of this issue. They appear to represent ANSI escape sequences like the ones found in the following packages.

I hope that was helpful.

@Hakerh400
Copy link

Those escape sequences (�[90m" and �[39m) are probably the most interesting part of this issue.

That is a known issue and unrelated to the issue from OP.

I would suggest moving this to nodejs/help, as it seems to be a problem with environment variables configuration, especially if the OP can confirm that https://github.com/nodejs/node/issues/32952#issuecomment-617356737 is the cause.

@jonerer
Copy link

jonerer commented Apr 23, 2020

This may or may not be related, but importing absolute paths on windows is not supported by ESM: nodejs/node#31710 . Currently the fix would be to convert your path to a "absolute file specifier" by doing something like

import { pathToFileURL } from 'url';
const fileUrl = pathToFileURL('c:\\path\\to\\file.js').href;
import(fileUrl);

@DerekNonGeneric
Copy link

/cc @addaleax as we now have a command associated w/ error message seen in #2266

@addaleax
Copy link
Member

@DerekNonGeneric I don’t really know that I can add any value here besides that a) this does belong in nodejs/help and I’ll move it there and b) this is an issue with Windows and/or npm, but not Node.js itself, as far as I can tell

@addaleax addaleax transferred this issue from nodejs/node Apr 24, 2020
@lukanp
Copy link
Author

lukanp commented Apr 25, 2020

I tried a lot of the things you recommended to me but nothing worked to fix the problem. In the end, I reinstalled my system and that's how I fixed it. Thank you for your support and advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants