当我生成一个带有角CLI (8.0.0)的项目时,我运行ng serve
,在Internet中打开应用程序,然后出现一个空白屏幕。
我查看了polyfills.ts
文件,并取消了以下行的注释:
import 'classlist.js';
import 'web-animations-js';
我还删除了所有core.js导入,因为Range8直接支持core.js 3.0。
我还运行过npm i
。
package.json:
"dependencies": {
"@angular/animations": "~8.0.0",
"@angular/common": "~8.0.0",
"@angular/compiler": "~8.0.0",
"@angular/core": "~8.0.0",
"@angular/forms": "~8.0.0",
"@angular/platform-browser": "~8.0.0",
"@angular/platform-browser-dynamic": "~8.0.0",
"@angular/router": "~8.0.0",
"classlist.js": "^1.1.20150312",
"rxjs": "~6.4.0",
"tslib": "^1.9.0",
"web-animations-js": "^2.3.1",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.800.0",
"@angular/cli": "~8.0.0",
"@angular/compiler-cli": "~8.0.0",
"@angular/language-service": "~8.0.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
}
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
编辑:
浏览器列表:
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11 # For IE 9-11 support, remove 'not'.
编辑2:
Internet (11)中的控制台显示以下错误:
polyfills.js:Syntax error (3168, 5)
(第3168行开头) -> class Zone {
vendor.js:Syntax error (156, 1)
(第156号开始) -> class PlatformLocation {
main.ts:Syntax error (95, 20)
(指向AppComponent)
我还需要做什么?
发布于 2019-06-13 03:43:10
根据这个问题的答复
您需要遵循以下步骤
tsconfig.es5.json
,内容如下{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es5"
}
}
angular.json
中的projects:yourAppName:architect:build:configurations
下,添加"es5": {
"tsConfig": "./tsconfig.es5.json"
}
和projects:yourAppName:architect:serve:configurations
添加
"es5": {
"browserTarget": "yourAppName:build:es5"
}
记住将app:build:es5中的yourAppName更改为yourAppName!
完整路径如下所示
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
...
},
"configurations": {
"production": {
...
},
"es5": {
"tsConfig": "./tsconfig.es5.json"
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
...
},
"configurations": {
"production": {
...
},
"es5": {
"browserTarget": "yourAppName:build:es5"
}
}
},
ng serve --configuration es5
发布于 2019-07-18 04:06:27
转到"tsconfig.json“并使用目标:"es5"而不是"target":"es2015",
目标在编译器内-- inside \编译程序选项
发布于 2019-09-17 12:27:38
您需要更改2个文件,分别是polyfills.ts
和tsconfig.json
。
只需在中添加浏览器
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/promise';
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';
在tsconfig.json
中,将"target“改为es5,如下所示
"target": "es5",
而不是
"target": "es2015",
https://stackoverflow.com/questions/56379067
复制相似问题