Angular2 CLI build EXCEPTION:选择器"app-root"与任何元素都不匹配 [英] Angular2 CLI build EXCEPTION : The selector "app-root" did not match any elements

查看:65
本文介绍了Angular2 CLI build EXCEPTION:选择器"app-root"与任何元素都不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从头开始,安装节点,输入文字,输入角度cli并运行命令 sudo ng new plzstart --mobile 创建项目,然后使用 sudo ng build strong>(在将cd转换为plzstart之后).

Started from scratch, installed node, typings, the angular cli and ran the command sudo ng new plzstart --mobile to create the project, then built it using sudo ng build (after performing a cd into plzstart).

build命令抛出以下异常:

The build command throws the following exception :

Apples-MacBook-Pro:plzstart apple$ sudo ng build
Password:
(node:45348) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
⠸ BuildingEXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: The selector "app-root" did not match any elements
ORIGINAL STACKTRACE:
Error: The selector "app-root" did not match any elements
    at new BaseException (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/facade/exceptions.js:17:23)
    at NodeDomRenderer.DomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:79:23)
    at DebugDomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/core/src/debug/debug_renderer.js:19:39)
    at DebugAppView.AppView.selectOrCreateHostElement (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:88:41)
    at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.template.js:12:21)
    at DebugAppView.AppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:66:21)
    at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:259:44)
    at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)
    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44
    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)
    at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)
    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)
    at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)
    at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)
ERROR CONTEXT:
DebugContext {
  _view: 
   DebugAppView {
     clazz: [Function: _View_AppComponent_Host0],
     componentType: 
      RenderComponentType {
        id: 'knu-0',
        templateUrl: '',
        slotCount: 0,
        encapsulation: 0,
        styles: [] },
     type: 0,
     viewUtils: 
      ViewUtils {
        _renderer: [Object],
        _appId: 'knu',
        _nextCompTypeId: 1,
        sanitizer: DomSanitizationServiceImpl {} },
     parentInjector: 
      ReflectiveInjector_ {
        _debugContext: null,
        _constructionCounter: 40,
        _proto: [Object],
        _parent: [Object],
        _strategy: [Object] },
     declarationAppElement: null,
     cdMode: 2,
     contentChildren: [],
     viewChildren: [],
     viewContainerElement: null,
     cdState: 2,
     destroyed: false,
     ref: ViewRef_ { _view: [Circular] },
     renderer: DebugDomRenderer { _delegate: [Object] },
     staticNodeDebugInfos: [ [Object] ],
     _currentDebugContext: [Circular],
     context: {},
     _hasExternalHostElement: true,
     projectableNodes: [] },
  _nodeIndex: 0,
  _tplRow: 0,
  _tplCol: 0 }
EXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: The selector "app-root" did not match any elements
ORIGINAL STACKTRACE:
Error: The selector "app-root" did not match any elements
    at new BaseException (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/facade/exceptions.js:17:23)
    at NodeDomRenderer.DomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:79:23)
    at DebugDomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/core/src/debug/debug_renderer.js:19:39)
    at DebugAppView.AppView.selectOrCreateHostElement (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:88:41)
    at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.template.js:12:21)
    at DebugAppView.AppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:66:21)
    at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:259:44)
    at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)
    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44
    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)
    at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)
    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)
    at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)
    at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)
ERROR CONTEXT:
DebugContext {
  _view: 
   DebugAppView {
     clazz: [Function: _View_AppComponent_Host0],
     componentType: 
      RenderComponentType {
        id: 'knu-0',
        templateUrl: '',
        slotCount: 0,
        encapsulation: 0,
        styles: [] },
     type: 0,
     viewUtils: 
      ViewUtils {
        _renderer: [Object],
        _appId: 'knu',
        _nextCompTypeId: 1,
        sanitizer: DomSanitizationServiceImpl {} },
     parentInjector: 
      ReflectiveInjector_ {
        _debugContext: null,
        _constructionCounter: 40,
        _proto: [Object],
        _parent: [Object],
        _strategy: [Object] },
     declarationAppElement: null,
     cdMode: 2,
     contentChildren: [],
     viewChildren: [],
     viewContainerElement: null,
     cdState: 2,
     destroyed: false,
     ref: ViewRef_ { _view: [Circular] },
     renderer: DebugDomRenderer { _delegate: [Object] },
     staticNodeDebugInfos: [ [Object] ],
     _currentDebugContext: [Circular],
     context: {},
     _hasExternalHostElement: true,
     projectableNodes: [] },
  _nodeIndex: 0,
  _tplRow: 0,
  _tplCol: 0 }
ngOnInit Error: { [Error: EXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: The selector "app-root" did not match any elements
ORIGINAL STACKTRACE:
Error: The selector "app-root" did not match any elements
    at new BaseException (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/facade/exceptions.js:17:23)
    at NodeDomRenderer.DomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:79:23)
    at DebugDomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/core/src/debug/debug_renderer.js:19:39)
    at DebugAppView.AppView.selectOrCreateHostElement (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:88:41)
    at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.template.js:12:21)
    at DebugAppView.AppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:66:21)
    at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:259:44)
    at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)
    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44
    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)
    at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)
    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)
    at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)
    at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)
ERROR CONTEXT:
[object Object]]
  _wrapperMessage: 'Error in :0:0',
  _originalException: 
   { Error: The selector "app-root" did not match any elements
       at new BaseException (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/facade/exceptions.js:17:23)
       at NodeDomRenderer.DomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:79:23)
       at DebugDomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/core/src/debug/debug_renderer.js:19:39)
       at DebugAppView.AppView.selectOrCreateHostElement (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:88:41)
       at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.template.js:12:21)
       at DebugAppView.AppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:66:21)
       at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:259:44)
       at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)
       at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44
       at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26
       at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)
       at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)
       at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)
       at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)
       at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)
       at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)
     message: 'The selector "app-root" did not match any elements',
     stack: 'Error: The selector "app-root" did not match any elements\n    at new BaseException (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/facade/exceptions.js:17:23)\n    at NodeDomRenderer.DomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:79:23)\n    at DebugDomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/core/src/debug/debug_renderer.js:19:39)\n    at DebugAppView.AppView.selectOrCreateHostElement (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:88:41)\n    at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.template.js:12:21)\n    at DebugAppView.AppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:66:21)\n    at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:259:44)\n    at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26\n    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)\n    at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)\n    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)\n    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)\n    at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)\n    at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)' },
  _originalStack: 'Error: The selector "app-root" did not match any elements\n    at new BaseException (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/facade/exceptions.js:17:23)\n    at NodeDomRenderer.DomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/platform-browser/src/dom/dom_renderer.js:79:23)\n    at DebugDomRenderer.selectRootElement (/Users/apple/PlzStart/node_modules/@angular/core/src/debug/debug_renderer.js:19:39)\n    at DebugAppView.AppView.selectOrCreateHostElement (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:88:41)\n    at DebugAppView._View_AppComponent_Host0.createInternal (AppComponent_Host.template.js:12:21)\n    at DebugAppView.AppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:66:21)\n    at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:259:44)\n    at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26\n    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)\n    at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)\n    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)\n    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)\n    at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)\n    at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)',
  _context: 
   DebugContext {
     _view: 
      DebugAppView {
        clazz: [Function: _View_AppComponent_Host0],
        componentType: [Object],
        type: 0,
        viewUtils: [Object],
        parentInjector: [Object],
        declarationAppElement: null,
        cdMode: 2,
        contentChildren: [],
        viewChildren: [],
        viewContainerElement: null,
        cdState: 2,
        destroyed: false,
        ref: [Object],
        renderer: [Object],
        staticNodeDebugInfos: [Object],
        _currentDebugContext: [Circular],
        context: {},
        _hasExternalHostElement: true,
        projectableNodes: [] },
     _nodeIndex: 0,
     _tplRow: 0,
     _tplCol: 0 },
  _wrapperStack: 'Error: Error in :0:0\n    at ViewWrappedException.WrappedException [as constructor] (/Users/apple/PlzStart/node_modules/@angular/core/src/facade/exceptions.js:34:31)\n    at new ViewWrappedException (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/exceptions.js:59:16)\n    at DebugAppView._rethrowWithContext (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:306:23)\n    at DebugAppView.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/view.js:262:18)\n    at ComponentFactory.create (/Users/apple/PlzStart/node_modules/@angular/core/src/linker/component_factory.js:143:36)\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:314:44\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:292:26\n    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)\n    at Object.NgZoneImpl.inner.inner.fork.onInvoke (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:45:41)\n    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:280:35)\n    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)\n    at NgZoneImpl.runInner (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone_impl.js:76:71)\n    at NgZone.run (/Users/apple/PlzStart/node_modules/@angular/core/src/zone/ng_zone.js:223:66)\n    at ApplicationRef_.run (/Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:290:14)\n    at ApplicationRef_.bootstrap (/Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:312:21)\n    at /Users/apple/PlzStart/node_modules/@angular/core/src/application_ref.js:100:50' }
Rendering Document Error: TypeError: Cannot read property '0' of undefined
    at /Users/apple/PlzStart/node_modules/angular2-universal/dist/node/bootloader.js:132:38
    at ZoneDelegate.invoke (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:281:29)
    at Zone.run (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:174:44)
    at /Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:529:58
    at ZoneDelegate.invokeTask (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:314:38)
    at Zone.runTask (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:214:48)
    at drainMicroTaskQueue (/Users/apple/PlzStart/node_modules/zone.js/dist/zone-node.js:432:36)
    at process._tickCallback (internal/process/next_tick.js:103:7)
Built project successfully. Stored in "dist/".

关于这是什么原因的任何线索吗?

Any clue as to what is the cause of this ?

推荐答案

使用以下命令启动新项目后,我遇到了同样的问题: ng new NAME --mobile之后,我这样做了:

I had the same issue after starting a new project with: ng new NAME --mobile after that I've done this:

  • rm -fR名称​​(以完全删除项目文件夹并重新开始)
  • ng new --mobile NAME --skip-npm (跳过npm步骤并稍后手动执行)
  • cd名称
  • 包中的 0.101.5 更改 angular2-univeral 版本. json "angular2-universal": "^0.100.3"
  • npm install (现在我们手动执行npm)
  • ng构建
  • ng服务器
  • rm -fR NAME (to remove project folder completely and start over)
  • ng new --mobile NAME --skip-npm (skip npm step and execute it manually later)
  • cd NAME
  • change the angular2-univeral version from 0.101.5 in package.json to "angular2-universal": "^0.100.3"
  • npm install (now we execute npm manually)
  • ng build
  • ng server

一切都很好.希望也能对您有所帮助,谢谢!

everything went well this time. I hope this will help you also, let me know, thanks!

这篇关于Angular2 CLI build EXCEPTION:选择器"app-root"与任何元素都不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆