简体   繁体   English

如何修复javascript错误导致jQuery无法在IE中正确加载?

[英]How to fix javascript error resulting in jQuery not loading properly in IE?

I'm debugging a problem that's recently affected our build and broke compatibility with Internet Explorer browsers. 我正在调试最近影响我们构建的问题并破坏了与Internet Explorer浏览器的兼容性。 We haven't changed our JavaScript codebase in months, but after a recent deployment, it seems jQuery's "$" stopped working in IE, breaking the page completely for that browser. 我们几个月没有改变我们的JavaScript代码库,但是在最近的部署之后,似乎jQuery的“$”停止在IE中工作,完全破坏了该浏览器的页面。 Most function calls on "$" return some form of "Object doesn't support property or method 'x'", and it seems that the "$" variable was assigned the wrong object in most cases. 对“$”的大多数函数调用返回某种形式的“对象不支持属性或方法'x'”,并且似乎在大多数情况下“$”变量被赋予了错误的对象。

jQuery's issue is just the most latent symptom, if I go around poking jQuery's "$" out of every error I come across, I eventually find similar issues with other variables. jQuery的问题只是最潜在的症状,如果我在我遇到的每个错误中调用jQuery的“$”,我最终会发现其他变量的类似问题。 But again, our codebase hasn't changed, only our build date. 但同样,我们的代码库没有改变,只有我们的构建日期。

I've tried looking for the easy stuff, like missing semi-colons or similar errors. 我已经尝试过寻找简单的东西,比如遗漏的冒号或类似的错误。 And I read on some other threads that another issue could be conflicting element id's on the page, but that doesn't seem to be the case either. 我在其他一些线程上读到另一个问题可能是页面上的元素id冲突,但情况似乎也不是这样。 I've tried reverting the codebase back to a couple of months ago, and also no joy. 我已经尝试将代码库恢复到几个月前,也没有任何乐趣。 I've considered infrastructure and network, but it happens on client machines and development machines, both inside and out of our internal net. 我考虑过基础架构和网络,但它发生在客户端机器和开发机器上,包括内部和内部网络。

The last thing that makes sense to me, since it stopped working around last Friday, is some update to one of the dependencies, as maybe when the deployment happened a dependency got updated and changed the final artifact on the build. 对我来说最后一件事,因为它在上周五停止工作,是对其中一个依赖项的一些更新,因为可能在部署发生时,依赖项得到更新并更改了构建的最终工件。 My hunch says that it's maybe Babel, but I don't know how I can confirm it, since I'm not familiar enough with Bower or the way Angular builds to prove it. 我的预感说它可能是Babel,但我不知道如何确认它,因为我对Bower或Angular构建的方式不够熟悉。

My working theory is that maybe Babel updated or something else caused the build to break recently (maybe babel-helper-evaluate-path?), since my research seems to point to that being a compiler for JavaScript so that it runs similarly on multiple platforms. 我的工作理论是,也许Babel更新或其他东西导致构建最近破坏(也许是babel-helper-evaluate-path?),因为我的研究似乎指出它是JavaScript的编译器,因此它在多个平台上运行类似。

 "devDependencies": {
    "babel-core": "6.26.3",
    "babel-helper-evaluate-path": "^0.5.0",
    "babel-preset-env": "1.7.0",
    "babel-preset-minify": "^0.5.0",
    "browser-sync": "^2.11.0",
    "del": "^1.2.0",
    "es6-promise": "^3.1.2",
    "express": "^4.13.4",
    "gulp": "^3.8.10",
    "gulp-angular-htmlify": "^0.4.0",
    "gulp-angular-templatecache": "^1.7.0",
    "gulp-babel": "7.0.1",
    "gulp-changed": "^1.1.0",
    "gulp-compass": "2.0.4",
    "gulp-concat": "^2.4.1",
    "gulp-css-flip": "^0.4.0",
    "gulp-cssnano": "^2.1.0",
    "gulp-expect-file": "0.0.7",
    "gulp-filter": "^2.0.2",
    "gulp-html-prettify": "0.0.1",
    "gulp-if": "^1.2.5",
    "gulp-ignore": "^1.2.1",
    "gulp-inject": "^1.3.1",
    "gulp-jshint": "^1.11.0",
    "gulp-jsvalidate": "^2.0.0",
    "gulp-less": "^1.3.9",
    "gulp-livereload": "^2.1.1",
    "gulp-load-plugins": "^0.10.0",
    "gulp-ng-annotate": "^2.0.0",
    "gulp-rename": "^1.2.0",
    "gulp-rtlcss": "^0.1.4",
    "gulp-sass": "^2.3.2",
    "gulp-sourcemaps": "^1.3.0",
    "gulp-sync": "^0.1.4",
    "gulp-uglify": "1.5.1",
    "gulp-util": "^3.0.1",
    "jshint-stylish": "^2.0.0",
    "less": "^1.7.5",
    "lodash": "^4.6.1",
    "lodash._basecreate": "^3.0.3",
    "lodash.isobject": "^3.0.2",
    "marked": "^0.3.2",
    "phantomjs-prebuilt": "^2.1.4",
    "rimraf": "2.2.8",
    "through2": "^0.6.3",
    "yargs": "^3.7.2"
  },

The initial error shows up on this line: 初始错误显示在此行上:

    var now = $.now(),
        promise;

Where the call to "$.now()" is broken as there isn't a jQuery reference inside of "$" on an IE runtime. 对“$ .now()”的调用被打破,因为IE运行时“$”中没有jQuery引用。

Take a look at your polyfills.ts and uncomment accordingly starting from here: 看看你的polyfills.ts并从这里开始相应取消注释:

    /**************** BROWSER POLYFILLS*****************/

/** IE9, IE10 and IE11 requires all of the following polyfills. **/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM