2016-02-19 49 views
6

我无法在Ubuntu 14.04上使用npm启动lite-server 2.1.0。我正在尝试运行Angular2快速入门示例。在运行Angular 2时遇到Linux错误或解决NPM lite-server错误快速入门

此问题可能特定于Linux,并且仅在最近更新到Ubuntu后才开始发生。我能够在Windows 8.1上成功运行Angular2快速入门。我已经尝试过各种不同版本的NPM和Node,但结果没有任何变化。运行Angular Heroes的例子也失败了,同样的问题。

任何解决方案或临时工作将不胜感激。

成功transpiling打字稿的JavaScript后,这里是试图通过NPM启动精简版服务器的结果:

npm run lite 

events.js:154 
     throw er; // Unhandled 'error' event 
    ^

Error: watch node_modules/insight/node_modules/lodash/internal/baseForOwnRight.js ENOSPC 
    at exports._errnoException (util.js:856:11) 
    at FSWatcher.start (fs.js:1313:19) 
    at Object.fs.watch (fs.js:1341:11) 
    at createFsWatchInstance (/tf/sbtf/ang2-reg/node_modules/chokidar/lib/nodefs-handler.js:37:15) 
    at setFsWatchListener (/tf/sbtf/ang2-reg/node_modules/chokidar/lib/nodefs-handler.js:80:15) 
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/tf/sbtf/ang2-reg/node_modules/chokidar/lib/nodefs-handler.js:228:14) 
    at FSWatcher.NodeFsHandler._handleFile (/tf/sbtf/ang2-reg/node_modules/chokidar/lib/nodefs-handler.js:255:21) 
    at FSWatcher.<anonymous> (/tf/sbtf/ang2-reg/node_modules/chokidar/lib/nodefs-handler.js:473:21) 
    at FSReqWrap.oncomplete (fs.js:82:15) 

npm ERR! Linux 3.19.0-49-generic 
npm ERR! argv "/tf/node/bin/node" "/tf/node/bin/npm" "run" "lite" 
npm ERR! node v5.6.0 
npm ERR! npm v3.7.2 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] lite: `lite-server` 
npm ERR! Exit status 1 

这里的的package.json。我确实将lite-server升级到了2.1.0,看看这会有所帮助,但事实并非如此。

{ 
    "name": "ang2-reg", 
    "version": "1.0.0", 
    "scripts": { 
    "postinstall": "npm run typings install", 
    "tsc": "tsc", 
    "tsc:w": "tsc -w", 
    "lite": "lite-server", 
    "start": "concurrent \"npm run tsc:w\" \"npm run lite\" ", 
    "typings" : "typings" 
    }, 
"license": "ISC", 
"dependencies": { 
    "angular2": "2.0.0-beta.6", 
    "bootstrap": "^3.3.6", 
    "systemjs": "0.19.20", 
    "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.14" 
    }, 
    "devDependencies": { 
    "concurrently": "^1.0.0", 
    "lite-server": "^2.1.0", 
    "typescript": "^1.8.0", 
    "typings":"^0.6.8" 
    } 
} 

这里的打字稿配置:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "system", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": false 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings/main", 
    "typings/main.d.ts" 
    ] 
} 

下面是来自NPM-的debug.log错误消息部分:

10 verbose lifecycle [email protected]~lite: CWD: /tf/sbtf/ang2-reg 
11 silly lifecycle [email protected]~lite: Args: [ '-c', 'lite-server' ] 
12 silly lifecycle [email protected]~lite: Returned: code: 1 signal: null 
13 info lifecycle [email protected]~lite: Failed to exec lite script 
14 verbose stack Error: [email protected] lite: `lite-server` 
14 verbose stack Exit status 1 
14 verbose stack  at EventEmitter.<anonymous> 
(/tf/node/lib/node_modules/npm/lib/utils/lifecycle.js:239:16) 
14 verbose stack  at emitTwo (events.js:100:13) 
14 verbose stack  at EventEmitter.emit (events.js:185:7) 
14 verbose stack  at ChildProcess.<anonymous> 
(/tf/node/lib/node_modules/npm/lib/utils/spawn.js:24:14) 
14 verbose stack  at emitTwo (events.js:100:13) 
14 verbose stack  at ChildProcess.emit (events.js:185:7) 
14 verbose stack  at maybeClose (internal/child_process.js:827:16) 
14 verbose stack  at Process.ChildProcess._handle.onexit 
(internal/child_process.js:211:5) 
15 verbose pkgid [email protected] 
16 verbose cwd /tf/sbtf/ang2-reg 
17 error Linux 3.19.0-49-generic 
18 error argv "/tf/node/bin/node" "/tf/node/bin/npm" "run" "lite" 
19 error node v5.6.0 
20 error npm v3.7.2 
21 error code ELIFECYCLE 
22 error [email protected] lite: `lite-server` 
22 error Exit status 1 
+0

我能够使用此命令自动转储:npm run tsc:w –

+0

这是由可怕的ENOSPC错误引起的。 –

回答

10

我有同样的错误,我可以在Ubuntu下一个步骤解决这个问题:

编辑文件/etc/sysctl.conf并添加下一行:

fs.inotify.max_user_watches = 524288 

保存文件并类型:

sudo sysctl -p 

然后再次运行npm start。 :)

+0

谢谢Andres!适用于我的Linux-Mint安装... –

+0

适用于我。谢谢!我很好奇,为什么这样能解决这个问题? –

+0

这也适用于我。实际上,当我指定32K而不是512K时,它甚至可以工作。但是,使用512K的影响实际上只是记忆。该号码似乎基于此链接:https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers号码本身可能没有什么神奇的。 –

1

如果你正在寻找一个解决方法的想法是使用NodeJS的版本4.x的

删除5.x的的NodeJS

sudo apt-get remove nodejs 

编辑源列表,使节点4.x版在回购

sudo nano /etc/apt/sources.list.d/nodesource.list 

然后在文件编辑两根线:

deb https://deb.nodesource.com/node_5.x vivid main 
deb-src https://deb.nodesource.com/node_5.x vivid main 

deb https://deb.nodesource.com/node_4.x vivid main 
deb-src https://deb.nodesource.com/node_4.x vivid main 

更新回购再次

sudo apt-get update 

,并重新安装节点

sudo apt-get install -y nodejs 

检查应wrtite像v4.3.1或V4.XX

node -v 

现在你可以运行versionm角向快速启动:

npm start 

希望它是有用的。

编辑:安装版本4后。的的NodeJS

在文件夹X,你有你的应用程序:

$ rm -r node_modules 

然后

npm install 

看起来愚蠢的,但是当你运行NPM安装它来编译某些模块,也许(我不知道)编译它们的方式随NodeJS版本而改变。

+0

不幸的是,这没有奏效。我以前试过这个,但又试了一次,看看我是否遗漏了一些东西。同样的问题,与“堆栈轨迹”略有不同的行号。 –

+0

似乎很明显,但是,在安装NodeJS v4.x之后,您是否尝试过删除node_modules文件夹并重新安装模块? – PablitoAM