0

I'm using npm install with advanced range, e.g. npm i karma@^1.0.0 and for Linux and OSX I get the latest version of package, but for windows platform, npm ignores range (caret symbol) and installs v.1.0.0

According to npm docs, I have to enclose version range with quotes. So, this npm i karma@"^1.0.0" works on windows properly.

Note that most version ranges must be put in quotes so that your shell will treat it as a single argument.

But why does it affect only windows? What might be the cause of this inconsistency?

npm - v.4.0.5

node - v.7.4.0

Thanks.

Bob
  • 773
  • 1
  • 10
  • 20
  • 1
    It's a different *shell*, I don't think npm deals with the arguments it receives any differently. Write a simple program that prints out the arguments it receives if you want to investigate how your shell is parsing the command. – jonrsharpe May 07 '17 at 07:45
  • it also occurs if I spawn `npm install` command, does it also related to shell? – Bob May 07 '17 at 07:51
  • What do you mean? – jonrsharpe May 07 '17 at 08:18
  • I've investigated `process.argv` array after installation with range and for this command `npm i carma@^1.0.0` argument's array look like: `[ 'C:\\Program Files\\nodejs\\node.exe', 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 'i', 'karma@1.0.0' ]` (caret symbol is removed) and for this command `npm i carma@~1.0.0` it looks like `[ 'C:\\Program Files\\nodejs\\node.exe', 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 'i', 'karma@~1.0.0' ]` (tilda symbol persists). How is it possible? – Bob May 07 '17 at 13:18
  • 1
    Evidently your shell isn't including the caret, which is why you need to put it in quotes. Looks like it's a special character in cmd.exe: http://windowsitpro.com/powershell/q-what-cmdexe-line-continuation-character – jonrsharpe May 07 '17 at 13:19
  • 1
    Yep, I guess windows shell is processing caret as special symbol (for line continuations or for escaping reserved shell characters like & | ( < > ^ according to this http://stackoverflow.com/questions/20342828/what-does-symbol-means-in-batch-script). – Bob May 07 '17 at 13:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143605/discussion-between-bob-and-jonrsharpe). – Bob May 07 '17 at 13:32
  • So it seems you should be able to provide your own answer here. The caret is a special symbol in Windows cmd.exe. See also [quoting and escaping](https://en.wikibooks.org/wiki/Windows_Batch_Scripting#Quoting_and_escaping). – jwdonahue Feb 02 '18 at 22:09

0 Answers0