我花了一些时间让它工作(据我所知)。
这是你必须做的(相反,这是我做了几次测试并且它有效)。按顺序执行这些步骤。
像往常一样使用 Angular cli 创建您的项目。
像往常一样,进入该项目目录。
删除节点模块。
单独安装 webpack(以确保您获得最新版本 ^2)。
npm install webpack
用下面的文件替换你的 package.json 文件,然后运行 npm install。
运行服务
项目启动。
请注意,在运行 ng serve 时,您会看到 20 多个这样的错误。他们似乎没有阻止项目运行,我在浏览器控制台中没有看到任何错误。
[default] /Users/tcoz/web-dev-projects/angular4/node_modules/@angular/platform-browser/typings/src/dom/dom_renderer.d.ts:58:41
Initializers are not allowed in ambient contexts.
另一件事:我没有全局安装 TS。不确定这是否重要,但可能。确保您运行的是最新版本 (^2.2.1)。
package.json(请注意,许多东西都更新了,不仅仅是角度,一些依赖消息令人困惑,直到我刚刚安装了 webpack 2):
{
"name": "angular4",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/compiler": "4.0.0-rc.1",
"@angular/core": "4.0.0-rc.1",
"@angular/common": "4.0.0-rc.1",
"@angular/forms": "4.0.0-rc.1",
"@angular/http": "4.0.0-rc.1",
"@angular/platform-browser": "4.0.0-rc.1",
"@angular/platform-browser-dynamic": "4.0.0-rc.1",
"@angular/router": "4.0.0-rc.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "4.0.0-rc.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.21",
"codelyzer": "3.0.0-beta.0",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"tslint": "^4.0.0",
"typescript": "^2.2.1",
"webdriver-manager": "10.2.5"
}
}