I’m encountering an issue with npm on my Windows machine. When I run npm --version
in the command line, I get the following output:
C:\Users\nares>npm --version
'CALL "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-prefix.js"' is not recognized as an internal or external command,
operable program or batch file.
10.8.2
I’ve tried:
- Reinstalling Node.js and npm multiple times.
- Checking the PATH environment variable to ensure it includes the paths to Node.js and npm.
- Running the command prompt as an administrator.
- Clearing the npm cache with
npm cache clean --force
Has anyone encountered this issue before?
Can you give more information, for example npm & node versions. And can you compare your npm-prefix.js
file with on this code:
// npm-prefix.js
#!/usr/bin/env node
// This is a single-use bin to help windows discover the proper prefix for npm
// without having to load all of npm first
// It does not accept argv params
const path = require('path')
const Config = require('@npmcli/config')
const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions')
const config = new Config({
npmPath: path.dirname(__dirname),
// argv is explicitly not looked at since prefix is not something that can be changed via argv
argv: [],
definitions,
flatten,
shorthands,
excludeNpmCwd: false,
})
async function main () {
try {
await config.load()
// eslint-disable-next-line no-console
console.log(config.globalPrefix)
} catch (err) {
// eslint-disable-next-line no-console
console.error(err)
process.exit(1)
}
}
main()