当前位置:  开发笔记 > 编程语言 > 正文

Angular2 QuickStart npm start无法正常工作

如何解决《Angular2QuickStartnpmstart无法正常工作》经验,为你挑选了7个好方法。

文件结构

我知道Angular2 beta刚刚发布,但我无法从他们的官方网站教程(https://angular.io/guide/quickstart)重现这些步骤.也许有人有类似的问题,知道该怎么做才能解决这个问题?当我尝试使用npm start命令启动应用程序时,我得到如下输出:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'start' ]
2 info using npm@2.7.4
3 info using node@v0.12.2
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart angular2-quickstart@1.0.0
6 info start angular2-quickstart@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info angular2-quickstart@1.0.0 Failed to exec start script
9 verbose stack Error: angular2-quickstart@1.0.0 start: `concurrent "npm run tsc:w" "npm run lite" `
9 verbose stack Exit status 127
9 verbose stack     at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:213:16)
9 verbose stack     at EventEmitter.emit (events.js:110:17)
9 verbose stack     at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:14:12)
9 verbose stack     at ChildProcess.emit (events.js:110:17)
9 verbose stack     at maybeClose (child_process.js:1015:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
10 verbose pkgid angular2-quickstart@1.0.0
11 verbose cwd /Users/tmrovsky/Documents/angular2/angular2-quickstart
12 error Darwin 13.4.0
13 error argv "node" "/usr/local/bin/npm" "start"
14 error node v0.12.2
15 error npm  v2.7.4
16 error code ELIFECYCLE
17 error angular2-quickstart@1.0.0 start: `concurrent "npm run tsc:w" "npm run lite" `
17 error Exit status 127
18 error Failed at the angular2-quickstart@1.0.0 start script 'concurrent "npm run tsc:w" "npm run lite" '.
18 error This is most likely a problem with the angular2-quickstart package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     concurrent "npm run tsc:w" "npm run lite"
18 error You can get their info via:
18 error     npm owner ls angular2-quickstart
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

我有:typescript 1.7.5版本节点0.12.2版本

也许有人可以帮助解决问题:)?

的package.json:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "license": "ISC",
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "systemjs": "0.19.6",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "zone.js": "0.5.10"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^1.3.1",
    "typescript": "^1.7.3"
  }
}

index.html的:




    Angular 2 QuickStart

    
    
    
    
    
    

    
    





Loading...



app.components.ts:

import {Component} from 'angular2/core';

@Component({
    selector: 'my-app',
    template: '

My First Angular 2 App

', }) export class AppComponent {}

boot.js:

import {bootstrap} from 'angular2/platform/browser'
import  {AppComponent} from './app.component'

bootstrap(AppComponent);

user60108.. 224

start从中更改package.json中的字段

"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" "

"start": "concurrently \"npm run tsc:w\" \"npm run lite\" "

有效!但为什么?开始在ng2中气馁. (9认同)

在Pluralsight Ward Bell的"play by play angular 2 quick start"课程中解释了这一点."tsc"首先编译代码,因为没有它,在更大的项目中,服务器可能在编译结束之前启动.在这种情况下,服务器会抛出一个错误,表明它不知道该怎么做. (9认同)

是的,为什么这样做?我想要一个解释 (5认同)

他为什么两次运行tsc(`tsc`和`tsc -w`)? (2认同)


小智.. 86

为了让npm start我跑步,我必须确保全局安装了一些devDependencies.你有没有尝试过:

npm install -g concurrently

npm install -g lite-server

npm install -g typescript

为我工作.`sudo npm update -g && sudo npm install -g concurrently lite-server typescript`. (11认同)

不要忘记卸载本地版本:`npm uninstall lite-server` (6认同)


小智.. 48

首先你需要更新npm,lite-server和typescript:

sudo npm update -g && sudo npm install -g concurrently lite-server typescript

从Angular项目目录中删除node_modules文件夹(如果存在).下次运行:

npm install

之后解决ENOSPC错误:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

最后:

npm start

这是我的package.json文件:

{
  "name": "reservationsystem",
  "version": "0.0.1",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "dependencies": {
    "a2-in-memory-web-api": "~0.1.0",
    "angular2": "2.0.0-beta.3",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "systemjs": "0.19.17",
    "zone.js": "0.5.11"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^2.0.1",
    "typescript": "^1.7.5"
  }
}



1> user60108..:

start从中更改package.json中的字段

"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" "

"start": "concurrently \"npm run tsc:w\" \"npm run lite\" "


有效!但为什么?开始在ng2中气馁.
在Pluralsight Ward Bell的"play by play angular 2 quick start"课程中解释了这一点."tsc"首先编译代码,因为没有它,在更大的项目中,服务器可能在编译结束之前启动.在这种情况下,服务器会抛出一个错误,表明它不知道该怎么做.
是的,为什么这样做?我想要一个解释
他为什么两次运行tsc(`tsc`和`tsc -w`)?

2> 小智..:

为了让npm start我跑步,我必须确保全局安装了一些devDependencies.你有没有尝试过:

npm install -g concurrently

npm install -g lite-server

npm install -g typescript


为我工作.`sudo npm update -g && sudo npm install -g concurrently lite-server typescript`.
不要忘记卸载本地版本:`npm uninstall lite-server`

3> 小智..:

首先你需要更新npm,lite-server和typescript:

sudo npm update -g && sudo npm install -g concurrently lite-server typescript

从Angular项目目录中删除node_modules文件夹(如果存在).下次运行:

npm install

之后解决ENOSPC错误:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

最后:

npm start

这是我的package.json文件:

{
  "name": "reservationsystem",
  "version": "0.0.1",
  "scripts": {
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "lite": "lite-server",
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" "
  },
  "dependencies": {
    "a2-in-memory-web-api": "~0.1.0",
    "angular2": "2.0.0-beta.3",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",
    "systemjs": "0.19.17",
    "zone.js": "0.5.11"
  },
  "devDependencies": {
    "concurrently": "^1.0.0",
    "lite-server": "^2.0.1",
    "typescript": "^1.7.5"
  }
}


4> dontHaveName..:

我在Windows 10上遇到了同样的错误.看起来它与npm包同时存在问题.我找到了2个选项来解决这个错误:

1.在两个单独的cmds中运行两个命令:

- 在第一次运行npm run tsc:w

- 在第二个npm run lite

2.更改package.json

- 只需更改启动选项:

npm run tsc:w


请注意.在Linux上:"开始":"tsc && npm run tsc:w&npm run lite",`

5> 小智..:

以下是我在尝试所有这些不同的解决方案后解决问题的方法 - (对于任何寻找另一种方式的人来说).

在快速入门目录中打开2个cmd实例:

窗口#1:

npm run build:watch

然后...

窗口#2:

npm run serve

然后它将在浏览器中打开并按预期工作



6> Michael Daus..:

复制angular2-quickstart文件夹(包括node_modules)以创建angular2-tour-of-heroes文件夹后,我遇到了类似的问题.这很奇怪,因为原版编译正常,但副本不是......

npm run tsc

我能够通过删除node_modules文件夹并重新运行npm install来解决此问题.

这对我来说是一个惊喜,所以我在两个文件夹之间做了一个差异......

diff -rw angular2-quickstart/node_modules/ angular2-tour-of-heroes/node_modules/

有很多差异,package.json文件中的很多'where'差异如下: -

diff -rw angular2-quickstart/node_modules/yargs/package.json angular2-tour-of-heroes/node_modules/yargs/package.json
5c5
<       "/Users/michael/Tutorials/angular2/angular2-quickstart/node_modules/lite-server"
---
>       "/Users/michael/Tutorials/angular2/angular2-tour-of-heroes/node_modules/lite-server"

...哪种有意义,但也有一些像这样: -

diff -rw angular2-quickstart/node_modules/utf-8-validate/build/gyp-mac-tool angular2-tour-of-heroes/node_modules/utf-8-validate/build/gyp-mac-tool
607c607,608
<       return {k: self._ExpandVariables(data[k], substitutions) for k in data}
---
>       return dict((k, self._ExpandVariables(data[k],
>                                             substitutions)) for k in data)

......我根本不明白.

哦,希望这会有所帮助.



7> 小智..:

更改package.json中的起始字段:

"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" "

至:

"start": "concurrently \"npm run tsc:w\" \"npm run lite\" "

它确实有帮助.

推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有