现象就是当F12打开Chrome devtools的时候,会弹出如下提示

lib is null:ko
lib is null:knockout

而且在Chrome devtools的Elements面板中,点击任何一个HTML element节点,都会弹出alert

经过在nc home中搜索,发现在/portal/frame/device_pc/script/compressed/3341564807.js (以及/portal/frame/device_pc/script/compressed/*.js)中,如下代码被调用了

function require(id, func, uuid) {
  ...
  var filelib = calculateAllLibs(id);
  ...
}
function calculateAllLibs(id) {
  ...
  calculateLibs(id, jsArr, cssArr, idArr);
  ...
}
function calculateLibs(id, jsArr, cssArr, idArr) {
  ...
  var lib = window.libArray[id];
  if (lib == null) {
    alert("lib is null:" + id);
    return;
  }

打断点,通过callstack查到是从Knockoutjs context debugger的这段代码调过来的。

calculateLibs (3341564807.js:1831)
calculateAllLibs (3341564807.js:1817)
require (3341564807.js:1784)
(anonymous function) (VM6207:13)
(anonymous function) (VM6207:128)

其中VM6207就是如下代码。

(function (shouldSerialize) {
    ...
	if( !ko){
		if(typeof window.require === 'function') {
			var isDefinedAvailable=typeof window.require.defined === 'function';
			try{
				if( (isDefinedAvailable && require.defined('ko')) || !isDefinedAvailable ){
					ko = require('ko');
				}
			} catch(e) { /*ingore */ }
			if(!ko){
				try{
					if( (isDefinedAvailable && require.defined('knockout')) || !isDefinedAvailable ){
						ko = require('knockout');
					}
				} catch(e) { /*ingore */ }
			}
		}
		if(!ko) {
			return {error:"knockout.js is not used in the page (ko is undefined). Maybe you are using iFrames, if so, browse to the url of the frame and try again."};
		}
	}
	...
})(true)

其中ko = require('ko')ko = require('knockout')调用了require函数,已经被3341564807.js重写了

解决办法就是暂时禁用knockjs插件。