1

我使用Angular2 Cli作为我的 Angular 2 应用程序的运行时环境。它的架构、一流的开发工具和整体的深思熟虑(因为没有更好的词) 给我留下了深刻的印象。

但是,大约每五次保存(构建)我的服务器就会生成错误消息:

Error: Trying to add a new entry to an already existing one:

然后我必须终止该进程并重新启动它以解决问题。

以下是全文:

file changed app/vtClass.ts
The Broccoli Plugin: [BroccoliTypeScriptCompiler] failed with:
Error: Trying to add a new entry to an already existing one: /home/vturner/vtstuff/angular/projects/ang2-cli2/tmp/broccoli_type_script_compiler-input_base_path-sdRX1KMo.tmp/0/src/app/ang2-cli2.spec.ts
    at BroccoliTypeScriptCompiler._addNewFileEntry (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:212:13)
    at /home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:159:38
    at Array.forEach (native)
    at BroccoliTypeScriptCompiler._doFullBuild (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:159:16)
    at BroccoliTypeScriptCompiler._doIncrementalBuild (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:116:12)
    at BroccoliTypeScriptCompiler.build (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:45:12)
    at /home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/broccoli-caching-writer/index.js:152:21
    at lib$rsvp$$internal$$tryCatch (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/rsvp/dist/rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/rsvp/dist/rsvp.js:1048:17)
    at lib$rsvp$$internal$$publish (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/rsvp/dist/rsvp.js:1019:11)

The broccoli plugin was instantiated at: 
    at BroccoliTypeScriptCompiler.Plugin (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/broccoli-plugin/index.js:10:31)
    at BroccoliTypeScriptCompiler.CachingWriter [as constructor] (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/broccoli-caching-writer/index.js:21:10)
    at BroccoliTypeScriptCompiler (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/broccoli-typescript.js:25:35)
    at Angular2App.toTree (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/lib/broccoli/angular2-app.js:67:16)
    at module.exports (/home/vturner/vtstuff/angular/projects/ang2-cli2/angular-cli-build.js:11:14)
    at Class.module.exports.Task.extend.setupBroccoliBuilder (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/node_modules/angular-cli/lib/models/builder.js:55:19)
    at Class.module.exports.Task.extend.init (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/node_modules/angular-cli/lib/models/builder.js:89:10)
    at new Class (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/core-object/core-object.js:18:12)
    at Class.module.exports.Task.extend.run (/home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/node_modules/angular-cli/lib/tasks/serve.js:15:19)
    at /home/vturner/vtstuff/angular/projects/ang2-cli2/node_modules/angular-cli/node_modules/angular-cli/lib/commands/serve.js:70:22

我似乎只在出现编码错误时才遇到问题,但这并不是说编码错误与此消息之间存在 1-1 对应关系——我生成的大多数编码错误都不会生成此消息。

一旦我收到错误,服务器似乎会进入阻塞状态,无论我做什么,包括修复编码问题,都会使问题消失。只有当我循环服务器时它才会消失。
不得不继续检查这种情况并循环服务器来解决这个问题变得非常乏味,这需要大约 6 秒。

我可以发布我的代码,但我没有看到代码和收到此消息之间的任何押韵或原因,所以我认为这不会有帮助,即我认为这是一个环境问题而不是编码问题。我尝试删除错误消息中列出的 tmp 目录,但这不起作用。

我像这样启动我的服务器:

vturner@vturner-virtual-machine ~/vtstuff/angular/projects/ang2-cli2 $ 
sudo ng serve 
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://www.ember-cli.com/user-guide/#watchman for more info.
Livereload server on http://localhost:49152
Serving on http://localhost:4200/

Build successful - 8049ms.

Slowest Trees                                 | Total               
----------------------------------------------+---------------------
BroccoliTypeScriptCompiler                    | 7643ms              

Slowest Trees (cumulative)                    | Total (avg)         
----------------------------------------------+---------------------
BroccoliTypeScriptCompiler (1)                | 7643ms              

file changed app/vtClass.ts

Build successful - 1072ms.

注意:我一直在以 sudo 运行服务器,因为我要么遇到权限问题,要么在某处读到它以 sudo 运行得更快(最后一个可能只在 Windows 上是真的),但我不认为以 sudo 运行与我的问题有关。

这是我的 package.json:

{
  "name": "ang2-cli2",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng server",
    "postinstall": "typings install --ambient",
    "lint": "tslint src/**/*.ts",
    "format": "clang-format -i -style=file --glob=src/**/*.ts",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "angular2": "2.0.0-beta.11",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.2",
    "systemjs": "0.19.20",
    "three": "^0.75.0",
    "zone.js": "^0.6.4"
  },
  "devDependencies": {
    "angular-cli": "0.0.*",
    "angular-cli-github-pages": "^0.2.0",
    "clang-format": "^1.0.35",
    "codelyzer": "0.0.12",
    "ember-cli-inject-live-reload": "^1.4.0",
    "jasmine-core": "^2.3.4",
    "jasmine-spec-reporter": "^2.4.0",
    "karma": "^0.13.15",
    "karma-chrome-launcher": "^0.2.1",
    "karma-jasmine": "^0.3.6",
    "protractor": "^3.0.0",
    "ts-node": "^0.5.5",
    "tslint": "^3.6.0",
    "typescript": "^1.8.7",
    "typings": "^0.6.6"
  }
}

谁能告诉我我做错了什么,或者我能做些什么来防止这种情况发生?

非常感谢。

4

1 回答 1

4

如果您是 Windows 用户,请在管理模式下运行您的终端。我遇到了同样的问题,它对我有用:)

于 2016-05-16T04:49:42.853 回答