2017-06-12 76 views
1

我想从angular.io运行教程。我在npm start时出错。 这是错误。我试图卸载所有npm,打字稿,节点,角度。错误的 第一部分:角度快速启动错误

npm WARN invalid config loglevel="notice" 
> [email protected] build C:\Users\Gia\quickstart 
> tsc -p src/ 
    src/app/app.component.spec.ts(3,50): error TS2307: Cannot find module '@angular/core/testing'. 
src/app/app.component.spec.ts(4,30): error TS2307: Cannot find module '@angular/platform-browser'. 
src/app/app.component.spec.ts(5,30): error TS2307: Cannot find module '@angular/core'. 
src/app/app.component.spec.ts(7,1): error TS2304: Cannot find name 'describe'. 
src/app/app.component.spec.ts(12,3): error TS2304: Cannot find name 'beforeEach'. 
src/app/app.component.spec.ts(19,3): error TS2304: Cannot find name 'beforeEach'. 
src/app/app.component.spec.ts(25,3): error TS2304: Cannot find name 'it'. 
src/app/app.component.spec.ts(25,39): error TS2304: Cannot find name 'expect'. 
src/app/app.component.spec.ts(27,3): error TS2304: Cannot find name 'it'. 
src/app/app.component.spec.ts(30,5): error TS2304: Cannot find name 'expect'. 
src/app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'. 
src/app/app.module.ts(1,31): error TS2307: Cannot find module '@angular/core'. 
src/app/app.module.ts(2,31): error TS2307: Cannot find module '@angular/platform-browser'. 
src/main.ts(1,40): error TS2307: Cannot find module '@angular/platform-browser-dynamic'. 

错误的第二部分:

npm ERR! code ELIFECYCLE 
    npm ERR! errno 2 
    npm ERR! [email protected] build: `tsc -p src/` 
    npm ERR! Exit status 2 
    npm ERR! 
    npm ERR! Failed at the [email protected] build script. 
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 

    npm ERR! A complete log of this run can be found in: 
    npm ERR!  C:\Users\Gia\AppData\Roaming\npm-cache\_logs\2017-06-12T15_05_48_144Z-debug.log 
    npm ERR! code ELIFECYCLE 
    npm ERR! errno 2 
    npm ERR! [email protected] prestart: `npm run build` 
    npm ERR! Exit status 2 
    npm ERR! 
    npm ERR! Failed at the [email protected] prestart script. 
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 

这里是文件的package.json:

{ 
     "name": "angular-quickstart", 
     "version": "1.0.0", 
     "description": "QuickStart package.json from the documentation, supplemented with testing support", 
     "scripts": { 
     "build": "tsc -p src/", 
     "build:watch": "tsc -p src/ -w", 
     "build:e2e": "tsc -p e2e/", 
     "serve": "lite-server -c=bs-config.json", 
     "serve:e2e": "lite-server -c=bs-config.e2e.json", 
     "prestart": "npm run build", 
     "start": "concurrently \"npm run tsc:w\" \"npm run serve\"", 
     "pree2e": "npm run build:e2e", 
     "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first", 
     "preprotractor": "webdriver-manager update", 
     "protractor": "protractor protractor.config.js", 
     "pretest": "npm run build", 
     "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", 
     "pretest:once": "npm run build", 
     "test:once": "karma start karma.conf.js --single-run", 
     "lint": "tslint ./src/**/*.ts -t verbose" 
     }, 
     "keywords": [], 
     "author": "", 
     "license": "MIT", 
     "dependencies": { 
     "@angular/common": "~4.0.0", 
     "@angular/compiler": "~4.0.0", 
     "@angular/core": "~4.0.0", 
     "@angular/forms": "~4.0.0", 
     "@angular/http": "~4.0.0", 
     "@angular/platform-browser": "~4.0.0", 
     "@angular/platform-browser-dynamic": "~4.0.0", 
     "@angular/router": "~4.0.0", 
     "angular": "^1.6.4", 
     "angular-in-memory-web-api": "~0.3.0", 
     "core-js": "^2.4.1", 
     "node": "0.0.0", 
     "rxjs": "5.0.1", 
     "systemjs": "0.19.40", 
     "zone.js": "^0.8.4" 
     }, 
     "devDependencies": { 
     "concurrently": "^3.2.0", 
     "lite-server": "^2.2.2", 
     "typescript": "~2.1.0", 
     "canonical-path": "0.0.2", 
     "tslint": "^3.15.1", 
     "lodash": "^4.16.4", 
     "jasmine-core": "~2.4.1", 
     "karma": "^1.3.0", 
     "karma-chrome-launcher": "^2.0.0", 
     "karma-cli": "^1.0.1", 
     "karma-jasmine": "^1.0.2", 
     "karma-jasmine-html-reporter": "^0.2.2", 
     "protractor": "~4.0.14", 
     "rimraf": "^2.5.4", 
     "@types/node": "^6.0.46", 
     "@types/jasmine": "2.5.36" 
     }, 
     "repository": {} 
    } 

这里是安装后NPM错误在应用文件夹中:

src/app/app.component.spec.ts(3,50): error TS2307: Cannot find module '@angular/core/testing'. 
src/app/app.component.spec.ts(4,30): error TS2307: Cannot find module '@angular/platform-browser'. 
src/app/app.component.spec.ts(5,30): error TS2307: Cannot find module '@angular/core'. 
src/app/app.component.ts(1,27): error TS2307: Cannot find module '@angular/core'. 
src/app/app.module.ts(1,31): error TS2307: Cannot find module '@angular/core'. 
src/app/app.module.ts(2,31): error TS2307: Cannot find module '@angular/platform-browser'. 
src/main.ts(1,40): error TS2307: Cannot find module '@angular/platform-browser-dynamic'. 
npm ERR! code ELIFECYCLE 
npm ERR! errno 2 
npm ERR! [email protected] build: `tsc -p src/` 
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the [email protected] build script. 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 

npm ERR! A complete log of this run can be found in: 
npm ERR!  C:\Users\Gia\AppData\Roaming\npm-cache\_logs\2017-06-12T15_26_01_665Z-debug.log 
npm ERR! code ELIFECYCLE 
npm ERR! errno 2 
npm ERR! [email protected] prestart: `npm run build` 
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the [email protected] prestart script. 
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
+1

看起来你缺少软件包。你尝试过运行'npm install'吗? – CodeWarrior

+0

是的。我做了,全球安装。 – pooh098

+0

我猜你可能已经在全球安装了一些dev依赖包。你可以尝试打开命令提示符/终端,导航到你的工作空间目录(package.json位于哪里)并运行这个确切的命令'npm install'? – CodeWarrior

回答

0

这些大多是测试文件中的错误或每个组件内缺少导入。您需要先解决所有这些问题,然后才能成功编译您的应用。它似乎不是一个错误。

我建议使用angular-cli创建一个新的角度应用程序,并继续从那里构建教程组件。 Angular-cli是创建角色应用程序和脚手架角色应用程序的官方工具。