2

I have tried to uninstall and reinstall angular cli, for which i have used,

sudo npm uninstall -g @angular/cli
sudo npm install -g @angular/cli

Whenever i give npm install it is showing the error,

npm ERR! Unexpected token < in JSON at position 1 while parsing near '
npm ERR! <!doctype html>
npm ERR! <htm...'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/izchnl050/.npm/_logs/2018-08-07T08_02_19_674Z-debug.log

And the log file consists the following,

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node',
1 verbose cli   '/usr/bin/npm',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   '@angular/cli' ]
2 info using npm@6.2.0
3 info using node@v10.8.0
4 verbose npm-session 6b584ff5794304f7
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://www.npmjs.com/@angular%2fcli 1450ms (from cache)
8 silly fetchPackageMetaData error for @angular/cli@latest Unexpected token < in JSON at position 1 while parsing near '
8 silly fetchPackageMetaData <!doctype html>
8 silly fetchPackageMetaData <htm...'
9 timing stage:rollbackFailedOptional Completed in 1ms
10 timing stage:runTopLevelLifecycles Completed in 1690ms
11 verbose stack SyntaxError: Unexpected token < in JSON at position 1 while parsing near '
11 verbose stack <!doctype html>
11 verbose stack <htm...'
11 verbose stack     at JSON.parse (<anonymous>)
11 verbose stack     at parseJson (/usr/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
11 verbose stack     at consumeBody.call.then.buffer (/usr/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
11 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
12 verbose cwd /home/izchnl050
13 verbose Linux 4.15.0-29-generic
14 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "@angular/cli"
15 verbose node v10.8.0
16 verbose npm  v6.2.0
17 error Unexpected token < in JSON at position 1 while parsing near '
17 error <!doctype html>
17 error <htm...'
18 verbose exit [ 1, true ]

Based on the other solutions, tried with the following,

npm cache clean --force

Uninstalled node and again installed node but there is no use.

If i give npm install it showing the above error everytime.

npm -v = 6.2.0
node -v = v10.8.0

Kindly help me to fix this issue and to continue with the workflow.

Maniraj Murugan
  • 8,868
  • 20
  • 67
  • 116
  • could you downgrade node version and try again?? – Akj Aug 07 '18 at 08:25
  • 1
    Seems like there is a connection issue and the request returns a HTML error page. Do you have an active internet connection? Are you behind a corporate proxy and if so, did you configure NPM proxy settings? – JSON Derulo Aug 07 '18 at 08:25
  • @UnluckyAj, IN node version 8 itself it throws the same error. Then only i have upgraded to node v 10.. – Maniraj Murugan Aug 07 '18 at 08:27
  • Are you behind a proxy? if you are add the proxy settings to npm. Or if that doen't work maybe you're using non-standard npm registry. check the registry url as well – Aritra Chakraborty Aug 07 '18 at 08:28
  • 1
    When using a custom npm registry, you might need to authenticate first. – JSON Derulo Aug 07 '18 at 08:28
  • Tried it in my local workspace using the same version of node and npm. And, I am able to install angular CLI without any problem. I assume that your problem is because there is some kind of proxy or you need to authenticate first before you're able to use internet (something akin to captive portal)... – kucing_terbang Aug 08 '18 at 05:26

1 Answers1

-2

try to remove package.lock file

Possible duplicate Install error: Unexpected token < in JSON at position

package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.

Delete the package-lock.json and after this run npm install.

Then you can install any plugin, that you want, with npm.

Akj
  • 7,038
  • 3
  • 28
  • 40
dev-assassin
  • 271
  • 2
  • 13