{"id":2554,"date":"2016-02-09T06:47:09","date_gmt":"2016-02-09T06:47:09","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=2554"},"modified":"2016-02-09T06:53:20","modified_gmt":"2016-02-09T06:53:20","slug":"why-am-i-getting-unexpected-token-u0000-when-using-npm-install-g-package-2","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/javascript\/nodejs\/why-am-i-getting-unexpected-token-u0000-when-using-npm-install-g-package-2\/","title":{"rendered":"Why am I getting Unexpected token &#8216;\\u0000&#8217; when using npm install -g package"},"content":{"rendered":"<blockquote><p>In this StackOverflow question I answered what to do when you get an unexpected token &#8216;\\u0000&#8217; error\u00a0when using npm install -g to install some package.<\/p><\/blockquote>\n<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[2554]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts, I will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>As you may know, I&#8217;m really into Ionic framework lately\u00a0and am helping out on StackOverflow with the knowledge I gained so far with the framework. I&#8217;m currently <strong>#3<\/strong> in the <a href=\"http:\/\/stackoverflow.com\/tags\/ionic\/topusers\">top All time answerers<\/a> list.<\/p>\n<p>I answered <a href=\"http:\/\/stackoverflow.com\/questions\/31547789\/why-am-i-getting-unexpected-token-u0000-when-using-npm-install-g-package\/31635673\">this question<\/a>\u00a0by user <a href=\"http:\/\/stackoverflow.com\/users\/784304\/bruce-whealton\">Bruce Whealton<\/a>:<\/p>\n<p>This is probably a Windows specific issue but I haven&#8217;t found any information when googling this issue. I had been using ionic framework which relies on Cordova (or Phonegap). However, the problem is not specific to any of these packages. I see this error quite often. So, the error is when I run a command such as the following:<\/p>\n<pre class=\"lang:default decode:true\">npm install -g cordova<\/pre>\n<p>However, I could substitute various other packages and get the same error. I&#8217;ll paste the snippet (very brief) below of the error message. What is strange is that I had an ionic project working in that directory earlier. Then today it told me that ionic could not be found. My hunch is that this is a different issue than the main issue I am describing here.<\/p>\n<p>I installed git bash so I do have a linux-like environment that I could try. I would just select Git Bash for a bash window with various bash commands. If there is an easier way to fix this for Windows users, please let me know. I have seen courses on Pluralsight where the instructors seem to be happily using npm with no problems. Also, when I use yeoman, I also at some point, in many cases, get the same error.<br \/>\nThe error is<\/p>\n<pre class=\"lang:default decode:true\">npm ERR! Failed to parse json\r\nnpm Unexpected token '\\u0000' at 1:1\r\nnpm ERR!\r\nnpm ERR! ^\r\nnpm ERR! File: c:\\Users\\Bruce\\AppData\\Roaming\\npm-cache\\amdefine\\1.0.0\\package\\package.json\r\nnpm ERR! Failed to parse package.json data.\r\nnpm ERR! package.json must be actual JSON, not just JavaScript.\r\nnpm ERR!\r\nnpm ERR! This is not a bug in npm\r\nnpm ERR! Tell the package author to fix their package.json file. JSON.parse.<\/pre>\n<p>Thanks in advance for any help\/advice, Bruce<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/31547789\/why-am-i-getting-unexpected-token-u0000-when-using-npm-install-g-package\/31635673#31635673\">My answer<\/a> was:<\/p>\n<blockquote><p>Via <a href=\"http:\/\/stackoverflow.com\/questions\/16280382\/cant-install-any-package-with-node-npm\">this question on SO<\/a> it could be that you just have to do:<\/p>\n<pre class=\"lang:default decode:true\">npm cache clean<\/pre>\n<p>But, also try the other methods suggested there like adding the registry option:<\/p>\n<pre class=\"lang:default decode:true \">npm install &lt;packagename&gt; --registry http:\/\/registry.npmjs.org\/.<\/pre>\n<p>Or, if you&#8217;ve been mingling with the <code>package.json<\/code> file by yourself, check if it&#8217;s valid.<\/p><\/blockquote>\n<blockquote class=\"twitter-tweet\" data-width=\"550\">\n<p lang=\"en\" dir=\"ltr\">Why am I getting Unexpected token \u2018u0000\u2019 when using <a href=\"https:\/\/twitter.com\/hashtag\/npm?src=hash\">#npm<\/a> install -g package <a href=\"https:\/\/twitter.com\/hashtag\/node?src=hash\">#node<\/a> <a href=\"https:\/\/t.co\/mjvmpMKuAT\">https:\/\/t.co\/mjvmpMKuAT<\/a> <a href=\"https:\/\/t.co\/HlqJ5S7PZ5\">pic.twitter.com\/HlqJ5S7PZ5<\/a><\/p>\n<p>&mdash; Nikola Bre\u017enjak (@HitmanHR) <a href=\"https:\/\/twitter.com\/HitmanHR\/status\/696949563349979138\">February 9, 2016<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this StackOverflow question I answered what to do when you get an unexpected token &#8216;\\u0000&#8217; error\u00a0when using npm install -g to install some package. I&#8217;m a big&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2555,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,35],"tags":[],"class_list":["post-2554","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nodejs","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=2554"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2554\/revisions"}],"predecessor-version":[{"id":2558,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2554\/revisions\/2558"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/2555"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=2554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=2554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=2554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}