gpt4 book ai didi

Angular2 CLI 生成异常 : The selector "app-root" did not match any elements

转载 作者:太空狗 更新时间:2023-10-29 17:20:41 32 4
gpt4 key购买 nike

从头开始,安装 node、typings、angular cli 并运行命令 sudo ng new plzstart --mobile 来创建项目,然后使用 sudo ng build (在将 cd 执行到 plzstart 之后)。

选择器“app-root”不匹配任何元素

构建命令抛出以下异常:

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/".

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

最佳答案

我在开始一个新项目后遇到了同样的问题:ng new NAME --mobile 完成后:

  • rm -fR NAME (完全删除项目文件夹并重新开始)
  • ng new --mobile NAME --skip-npm (跳过 npm 步骤,稍后手动执行)
  • cd 名称
  • package 中将 angular2-univeral 版本从 0.101.5 更改。 json"angular2-universal": "^0.100.3"
  • npm install (现在我们手动执行 npm)
  • 构建
  • ng 服务器

这次一切顺利。我希望这对你也有帮助,让我知道,谢谢!

关于Angular2 CLI 生成异常 : The selector "app-root" did not match any elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37840778/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com