AngularJS 2:运行(非常)基本应用程序

时间:2016-09-16 22:56:57

标签: node.js angular

我试图运行first basic example of AngularJS 2 但是当我尝试运行应用程序(在我的文件夹项目中的npm start)时,我收到了以下错误消息:

angular2-quickstart@1.0.0 start /home/waterbed/xxxy
tsc && concurrently "npm run tsc:w" "npm run lite"

app/app.component.ts(3,10): error TS2305: Module '"/home/waterbed/xxxy/app/app.component"' has no exported member 'AppComponent'.
app/main.ts(2,27): error TS2307: Cannot find module './app.module'.

npm ERR! Linux 3.16.0-4-586
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.4.5
npm ERR! npm  v2.15.5
npm ERR! code ELIFECYCLE
npm ERR! angular2-quickstart@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the angular2-quickstart@1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" '.
npm ERR! This is most likely a problem with the angular2-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     tsc && concurrently "npm run tsc:w" "npm run lite"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular2-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls angular2-quickstart
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/waterbed/xxxy/npm-debug.log

错误,消息似乎很明显,但谷歌的指南从未提及创建app.module。

tree ./app返回:

app/
├── app.component.js
├── app.component.js.map
├── app.component.ts
├── app.modules.js
├── app.modules.js.map
├── app.modules.ts
├── main.js
├── main.js.map
└── main.ts

更不用说我是AngularJS的新手,无论我们谈论什么版本,我对npm,nodejs几乎都是新手......

3 个答案:

答案 0 :(得分:1)

首先查看你的app.component,如果没有导出AppComponent类,则在class关键字之前输出。还要检查您的文件是否与angular2示例应用程序具有相同的代码。也许你忘记了什么。

尝试更新您的npm版本(节点包管理器) npm更新

npm update -g

答案 1 :(得分:0)

您的app.component.ts正在寻找app.module.ts,但您的文件结构中没有该文件。尝试重命名

app.modules.ts

app.module.ts

答案 2 :(得分:0)

因此,编码Mon键表示app.module.ts未正确命名。 但我还必须做以下事情:

  1. rm -rf node_modules
    • npm install
    • npm run typings install
  2. copy再次包含来自Angular JS快速入门的以下文件:
  3. 应用程序/ main.ts   从'@ angular / platform-b​​rowser-dynamic'导入{platformBrowserDynamic};   从'./app.module'导入{AppModule};   const platform = platformBrowserDynamic();   platform.bootstrapModule(的AppModule);
  4. 应用程序/ app.module.ts   从'@ angular / core'导入{NgModule};   从'@ angular / platform-b​​rowser'导入{BrowserModule};   从'./app.component'导入{AppComponent};   @NgModule({      导入:[BrowserModule],      声明:[AppComponent],      bootstrap:[AppComponent]   })   导出类AppModule {}
  5. 应用程序/ app.component.ts  从'@ angular / core'导入{Component};  @零件({      选择器:'my-app',      模板:'

    My First Angular App

    '  })  export class AppComponent {}