npm ERR! Unexpected token <

  git, question

Problem description

  • Jenkins has deployed two tasks, int and dev
  • Int and dev use the same server and the environment is the same.
  • Dev can be built normally and automatically. int reports the above error
  • If you put dev’s code into int’s build environment, you will still report the above error.
  • Int can normally execute npm build in local webstorm.

The environmental background of the problem and what methods have you tried?

1. delete the package-lock.json file under the root directory; Json file is modified and submitted.

Still reporting the same mistake

3. Set to the original npm address:

a、npm config set registry  http://registry.npmjs.org
 B. error reporting: code EINTEGRITY
 C the online solution is to use Taobao's mirror image (back to the first question)

Related codes

//Please paste the code text below (please do not replace the code with pictures)
Shell script:
npm -v
npm install
npm run build
rm -rf /usr/local/nginx/html/stbs-web/dist
cp -r dist /usr/local/nginx/html/stbs-web/

What is your expected result? What is the actual error message?

Error message 01:

npm -v
6.2.0
npm config set registryhttp://registry.npm.taobao.org/
npm config get registry
http://registry.npm.taobao.org/
npm install
npm ERR! Unexpected token < in JSON at position 0 while parsing near ‘<html>
npm ERR! <head>
npm ERR! …’

npm ERR! A complete log of this run can be found in:
npm ERR! /home/sunshangpan/.npm/_logs/2018-10-29T07_20_32_983Z-debug.log
Build step ‘Execute shell’ marked build as failure
Finished: FAILURE

Error message in command line (inexplicably downloaded a file, causing json parsing to report an error)

npm ERR! <html>
npm ERR! <head>
npm ERR! <script type=”text/javascript”>
npm ERR! /*
npm ERR! :: Description of the situation
npm ERR! *
npm ERR! * (1) Controls
npm ERR! * 1 > control permissions, select disable
npm ERR! *-> jump to redirection page, unable to obtain PC information
npm ERR! *
npm ERR! * 2 > control permissions, select enable
npm ERR! *-> jump to the redirection page to obtain PC information
npm ERR! *
npm ERR! * 3 > control permissions, select prompt
npm ERR! * pop-up controls, click is-> jump to the redirect page, get PC information
npm ERR! * no-> jump to redirection page, unable to obtain PC information
npm ERR! *
npm ERR! * base64 encryption
npm ERR! */
npm ERR! //js-base64 encryption
npm ERR! function Base64() {
npm ERR! // private property
npm ERR! _keyStr = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=”;
npm ERR!
npm ERR! // public method for encoding
npm ERR! this.encode = function (input) {
npm ERR! var output = “”;
npm ERR! var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
npm ERR! var i = 0;
npm ERR! input = _utf8_encode(input); //Turn to utf-8
npm ERR! while (i < input.length) {
npm ERR! chr1 = input.charCodeAt(i++); //Returns the unicode encoding of the specified location
npm ERR! chr2 = input.charCodeAt(i++);
npm ERR! chr3 = input.charCodeAt(i++);
npm ERR! enc1 = chr1 >> 2;
npm ERR! enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
npm ERR! enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
npm ERR! enc4 = chr3 & 63;
npm ERR! if (isNaN(chr2)) {
npm ERR! enc3 = enc4 = 64;
npm ERR! } else if (isNaN(chr3)) {
npm ERR! enc4 = 64;
npm ERR! }
npm ERR! output = output +
npm ERR! _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
npm ERR! _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
npm ERR! }
npm ERR! return output;
npm ERR! }
npm ERR!
npm ERR! // public method for decoding
npm ERR! this.decode = function (input) {
npm ERR! var output = “”;
npm ERR! var chr1, chr2, chr3;
npm ERR! var enc1, enc2, enc3, enc4;
npm ERR! var i = 0;
npm ERR! input = input.replace(/1/g, “”);
npm ERR! while (i < input.length) {
npm ERR! enc1 = _keyStr.indexOf(input.charAt(i++)); //charAt specifies the char value of the index position, and indexOf retrieves the position where the string first appears
npm ERR! enc2 = _keyStr.indexOf(input.charAt(i++));
npm ERR! enc3 = _keyStr.indexOf(input.charAt(i++));
npm ERR! enc4 = _keyStr.indexOf(input.charAt(i++));
npm ERR! chr1 = (enc1 << 2) | (enc2 >> 4);
npm ERR! chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
npm ERR! chr3 = ((enc3 & 3) << 6) | enc4;
npm ERR! output = output + String.fromCharCode(chr1); //Accept a specified unicode value and return a string
npm ERR! if (enc3 ! = 64) {
npm ERR! output = output + String.fromCharCode(chr2);
npm ERR! }
npm ERR! if (enc4 ! = 64) {
npm ERR! output = output + String.fromCharCode(chr3);
npm ERR! }
npm ERR! }
npm ERR! output = _utf8_decode(output);
npm ERR! return output;
npm ERR! }
npm ERR!
npm ERR! // private method for UTF-8 encoding
npm ERR! _utf8_encode = function (string) {
npm ERR! string = string.replace(/rn/g,”n”);
npm ERR! var utftext = “”;
npm ERR! for (var n = 0; n < string.length; n++) {
npm ERR! var c = string.charCodeAt(n);
npm ERR! if (c < 128) {
npm ERR! utftext += String.fromCharCode(c);
npm ERR! } else if((c > 127) && (c < 2048)) {
npm ERR! utftext += String.fromCharCode((c >> 6) | 192);
npm ERR! utftext += String.fromCharCode((c & 63) | 128);
npm ERR! } else {
npm ERR! utftext += String.fromCharCode((c >> 12) | 224);
npm ERR! utftext += String.fromCharCode(((c >> 6) & 63) | 128);
npm ERR! utftext += String.fromCharCode((c & 63) | 128);
npm ERR! }
npm ERR!
npm ERR! }
npm ERR! return utftext;
npm ERR! }
npm ERR!
npm ERR! // private method for UTF-8 decoding
npm ERR! _utf8_decode = function (utftext) {
npm ERR! var string = “”;
npm ERR! var i = 0;
npm ERR! var c = c1 = c2 = 0;
npm ERR! while ( i < utftext.length ) {
npm ERR! c = utftext.charCodeAt(i);
npm ERR! if (c < 128) {
npm ERR! string += String.fromCharCode(c);
npm ERR! i++;
npm ERR! } else if((c > 191) && (c < 224)) {
npm ERR! c2 = utftext.charCodeAt(i+1);
npm ERR! string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
npm ERR! i += 2;
npm ERR! } else {
npm ERR! c2 = utftext.charCodeAt(i+1);
npm ERR! c3 = utftext.charCodeAt(i+2);
npm ERR! string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
npm ERR! i += 3;
npm ERR! }
npm ERR! }
npm ERR! return string;
npm ERR! }
npm ERR! }
npm ERR! //Judge whether the control is created
npm ERR! function DetectActiveX(a){
npm ERR! try
npm ERR! {
npm ERR! var comActiveX = new ActiveXObject(a);
npm ERR! }
npm ERR! catch(e)
npm ERR! {
npm ERR! return false;
npm ERR! }
npm ERR! return true;
npm ERR! }
npm ERR! var url=document.URL;
npm ERR! var aryUrl = url.split(‘=’);
npm ERR! var aryLength = aryUrl.length;
npm ERR!
npm ERR! //main
npm ERR! var userVisitUrl = ”;
npm ERR! if(aryLength > 1) {
npm ERR! var lengt = aryUrl[0];
npm ERR! var leng = lengt.length;
npm ERR! var length = leng + 1;
npm ERR! var urlOne = url.substr(0, length);
npm ERR! var urlRedirect = url.replace(urlOne, “”);
npm ERR! var userVisitUrl = urlRedirect.replace(/(^s)|(s$)/g, “”);
npm ERR! }
npm ERR!
npm ERR! var userNameBase = ”;
npm ERR! var userDomainBase = ”;
npm ERR! if(DetectActiveX(“WScript.Network”)){
npm ERR! var WshNetwork = new ActiveXObject(“WScript.Network”);
npm ERR! // document.write(typeof(WshNetwork)+”
“);
npm ERR! // document.write(WshNetwork.UserDomain+”
“+WshNetwork.ComputerName+”
“+WshNetwork.UserName+”
“);
npm ERR! computerName = WshNetwork.ComputerName;
npm ERR! userDomain = WshNetwork.UserDomain;
npm ERR! userName = WshNetwork.UserName;
npm ERR! document.write(userName + ‘//’ + userDomain+’
‘);
npm ERR! var b = new Base64();
npm ERR! var userNameBase = b.encode(userName);
npm ERR! var userDomainBase = b.encode(userDomain);
npm ERR! // document.write(userNameBase+’//’+userDomainBase+’
‘);
npm ERR! // strd1 = b.decode(userNameBase);
npm ERR! // strd2 = b.decode(userDomainBase);
npm ERR! // document.write(strd1+’//’+strd2+’
‘);
npm ERR! }
npm ERR!
npm ERR! </script>
npm ERR! </head>
npm ERR! <body>
npm ERR! <form name=”mainform” action=”/login” method=”post”>
npm ERR! <input type=hidden id=”login_type” name=”login_type” value=’logincheck’>
npm ERR! <input type=”hidden” id=”selfLogin” name=”selfLogin” value=”” />
npm ERR! <input type=”hidden” id=”selfGroup” name=”selfGroup” value=”” />
npm ERR! <input type=”hidden” id=”userVisitUrl” name=”userVisitUrl” value=”” />
npm ERR! <script language=”JavaScript” type=”text/JavaScript”>
npm ERR! if(userNameBase ! = ” && userDomainBase ! = ”){
npm ERR! document.getElementById(‘selfLogin’).value = userNameBase;
npm ERR! document.getElementById(‘selfGroup’).value = userDomainBase;
npm ERR! }else if(userNameBase ! = ” && userDomainBase == ”){
npm ERR! document.getElementById(‘selfLogin’).value = userNameBase;
npm ERR! document.getElementById(‘selfGroup’).value = ”;
npm ERR! }else if(userNameBase == ” && userDomainBase ! = ”){
npm ERR! document.getElementById(‘selfLogin’).value = ”;
npm ERR! document.getElementById(‘selfGroup’).value = userDomainBase;
npm ERR! }else if(userNameBase == ” && userDomainBase == ”){
npm ERR! document.getElementById(‘selfLogin’).value = ”;
npm ERR! document.getElementById(‘selfGroup’).value = ”;
npm ERR! }
npm ERR! document.getElementById(‘userVisitUrl’).value = userVisitUrl;
npm ERR! document.mainform.submit();
npm ERR! </script>
npm ERR! </form>
npm ERR! </body>
npm ERR! </html>


  1. A-Za-z0-9+/=

The reason was found: the server where jenkins was deployed was not connected to the network due to the power failure before, and the download file could not be found during npm install