gpt4 book ai didi

Angular 8,启动时出现 IE11 错误 Function.prototype.toString : 'this' is not a Function object

转载 作者:行者123 更新时间:2023-12-04 04:24:01 24 4
gpt4 key购买 nike

自升级到 Angular 8 后,使用 Angular CLI 的生产构建在 IE11 中启动时失败。控制台中记录的错误是:“Function.prototype.toString: 'this' is not a Function object”并指向 polyfills-es5.js。

polyfills-es5.js 中有问题的部分是:

var InternalStateModule = __webpack_require__(
/*! ../internals/internal-state */
"./node_modules/core-js/internals/internal-state.js");

var getInternalState = InternalStateModule.get;
var enforceInternalState = InternalStateModule.enforce;
var TEMPLATE = String(nativeFunctionToString).split('toString');
shared('inspectSource', function (it) {
return nativeFunctionToString.call(it);
});
(module.exports = function (O, key, value, options) {
var unsafe = options ? !!options.unsafe : false;
var simple = options ? !!options.enumerable : false;
var noTargetGet = options ? !!options.noTargetGet : false;

if (typeof value == 'function') {
if (typeof key == 'string' && !has(value, 'name')) hide(value, 'name', key);
enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
}

if (O === global) {
if (simple) O[key] = value; else setGlobal(key, value);
return;
} else if (!unsafe) {
delete O[key];
} else if (!noTargetGet && O[key]) {
simple = true;
}

if (simple) O[key] = value; else hide(O, key, value); // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
})(Function.prototype, 'toString', function toString() {
return typeof this == 'function' && getInternalState(this).source || nativeFunctionToString.call(this);
});

我从头开始创建了一个新应用,显然它在 IE11 中运行良好。因此,我尝试向后工作并删除包/更改配置,直到它与默认应用匹配,但继续出现错误。

比较两者生成的 polyfills-es5.js 文件,它们是不同的,但我找不到任何关于该文件是如何生成的信息(我的 polyfills.ts 文件与默认应用程序相同)。

我不知道如何进一步解决它。

最佳答案

在 tsconfig.json 中,目标为 es5(默认为 es6)。在 polyfills.ts 中,取消注释 IE polyfills。

  "compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}

Polyfills.ts


* BROWSER POLYFILLS
*/

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';


/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';


关于Angular 8,启动时出现 IE11 错误 Function.prototype.toString : 'this' is not a Function object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58297190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com