在我的主题中,我在https://github.com/angular/angular/blob/master/CHANGELOG.md
之后添加了解决方法 ///<reference path="../../../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from '../../../node_modules/angular2/platform/browser'
import {AppComponent} from './app.component'
// Add all operators to Observable
import 'rxjs/Rx'
bootstrap(AppComponent);
在tsconfig.json中,不包括browser.d.ts和浏览器。
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"typings/browser.d.ts",
"typings/browser",
"node_modules"
]
}
在我的index.html的头脑中
app.use('/scripts', express.static(__dirname + '/node_modules'));
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="/scripts/es6-shim/es6-shim.min.js"></script>
<script src="/scripts/systemjs/dist/system-polyfills.js"></script>
<script src="/scripts/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="/scripts/angular2/bundles/angular2-polyfills.js"></script>
<script src="/scripts/systemjs/dist/system.src.js"></script>
<script src="/scripts/rxjs/bundles/Rx.js"></script>
<script src="/scripts/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('../js/acApp/main.ts')
.then(null, console.error.bind(console));
</script>
的package.json
{
"name": "AC",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "concurrently \"npm run tsc:w\" \"nodemon server.js\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
},
"dependencies": {
"bcrypt-nodejs": "*",
"body-parser": "*",
"cookie-parser": "*",
"ejs": "*",
"errorhandler": "*",
"express": "4.x",
"express-json": "*",
"express-session": "*",
"method-override": "*",
"morgan": "*",
"mysql": "*",
"nodemon": "^1.9.1",
"passport": "*",
"passport-local": "*",
"serve-favicon": "*",
"bcrypt":"*",
"cookie-parser":"*",
"express-session":"*",
"bookshelf":"*",
"passport": "*",
"passport-local": "*",
"knex":"*",
"log4js":"*",
"express-session":"*",
"angular2": "*",
"traceur":"*",
"systemjs": "*",
"es6-promise": "*",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "^0.6.4"
},
"devDependencies": {
"concurrently": "^2.0.0",
"lite-server": "^2.1.0",
"typescript": "^1.8.9",
"typings":"^0.7.9"
}
}
但我仍然有重复的错误。有什么想法吗?
[0] 16:47:12 - File change detected. Starting incremental compilation...
[0] node_modules/angular2/typings/browser.d.ts(6,14): error TS2300: Duplicate identifier 'PromiseConstructor'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(22,5): error TS2300: Duplicate identifier 'done'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(23,5): error TS2300: Duplicate identifier 'value'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(46,5): error TS2300: Duplicate identifier 'size'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(52,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(66,5): error TS2300: Duplicate identifier 'size'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(72,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(88,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-collections/es6-collections.d.ts(103,5): error TS2300: Duplicate identifier 'prototype'.
[0] node_modules/angular2/typings/es6-promise/es6-promise.d.ts(11,15): error TS2300: Duplicate identifier 'Promise'.
[0] node_modules/angular2/typings/es6-promise/es6-promise.d.ts(42,16): error TS2300: Duplicate identifier 'Promise'.
[0] public/js/acApp/app.component.ts(3,2): error TS2304: Cannot find name 'Component'.
[0] public/js/acApp/app.component.ts(8,2): error TS2304: Cannot find name 'View'.
[0] public/js/acApp/app.component.ts(21,16): error TS2304: Cannot find name 'RouterOutlet'.
[0] public/js/acApp/app.component.ts(23,2): error TS2304: Cannot find name 'RouteConfig'.
[0] public/js/acApp/app.component.ts(24,69): error TS2304: Cannot find name 'UserTimelineComponent'.
[0] typings/main/ambient/es6-shim/index.d.ts(11,5): error TS2300: Duplicate identifier 'done'.
[0] typings/main/ambient/es6-shim/index.d.ts(12,5): error TS2300: Duplicate identifier 'value'.
[0] typings/main/ambient/es6-shim/index.d.ts(477,11): error TS2300: Duplicate identifier 'Promise'.
[0] typings/main/ambient/es6-shim/index.d.ts(496,11): error TS2300: Duplicate identifier 'PromiseConstructor'.
[0] typings/main/ambient/es6-shim/index.d.ts(554,13): error TS2300: Duplicate identifier 'Promise'.
[0] typings/main/ambient/es6-shim/index.d.ts(563,5): error TS2300: Duplicate identifier 'size'.
[0] typings/main/ambient/es6-shim/index.d.ts(572,5): error TS2300: Duplicate identifier 'prototype'.
[0] typings/main/ambient/es6-shim/index.d.ts(583,5): error TS2300: Duplicate identifier 'size'.
[0] typings/main/ambient/es6-shim/index.d.ts(592,5): error TS2300: Duplicate identifier 'prototype'.
[0] typings/main/ambient/es6-shim/index.d.ts(607,5): error TS2300: Duplicate identifier 'prototype'.
[0] typings/main/ambient/es6-shim/index.d.ts(621,5): error TS2300: Duplicate identifier 'prototype'.
更新
@Eric,
韩国社交协会。我从angular2文件夹中删除了browser.d.ts.重复错误消失了。然后,我必须删除///<reference path="node_modules/angular2/typings/browser.d.ts"/>
,因为它会导致找不到文件错误。剩下的错误是,
[0] public/js/acApp/app.component.ts(3,2): error TS2304: Cannot find name 'Component'.
[0] public/js/acApp/app.component.ts(8,2): error TS2304: Cannot find name 'View'.
[0] public/js/acApp/app.component.ts(21,16): error TS2304: Cannot find name 'RouterOutlet'.
[0] public/js/acApp/app.component.ts(23,2): error TS2304: Cannot find name 'RouteConfig'.
[0] public/js/acApp/app.component.ts(24,69): error TS2304: Cannot find name 'UserTimelineComponent'.
我的文件夹结构是
-node_modules
-public
--js
---acApp
----main.ts
----app.component.js
错误