Work Around or Fix for NPM lite-server on Linux error when running Angular 2 Quick Start
Asked Answered
R

2

6

I am unable to start the lite-server 2.1.0 using npm on Ubuntu 14.04. I am trying to run the Angular2 Quick Start example.

This problem may be specific to Linux and only started to occur after a recent update to Ubuntu. I am able to run the Angular2 Quick Start successfully on Windows 8.1. I have tried various different versions of NPM and Node with no changes in my results. Running the Angular Heroes example also fails with the same issue.

Any solution or temporary work around would be greatly appreciated.

After successfully transpiling typescript to javascript, here is the result of attempting to start lite-server via 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

Here's the package.json. I did upgrade lite-server to 2.1.0 to see if that would help, but it did not.

{
  "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"
  }
}

Here's the typescript config:

{
  "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"
  ]
}

Here's the error message portion from the 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
Raffinose answered 19/2, 2016 at 19:3 Comment(2)
I am able auto transpile with this command: npm run tsc:wRaffinose
This was caused by the dreaded ENOSPC error.Raffinose
F
10

I had the same error and I can solve it in ubuntu with the next steps:

Edit the file /etc/sysctl.conf and add the next line:

fs.inotify.max_user_watches = 524288

Save the file and type:

sudo sysctl -p

And try again run npm start. :)

Fanchet answered 25/2, 2016 at 3:46 Comment(3)
Works for me too. Thanks! I'm curios, why did this fix the problem?Raffinose
This worked for me as well. In fact, it even worked when I specified 32K instead of 512K. However, the impact of using 512K is really just memory. The number appears to be based off this link: github.com/guard/listen/wiki/… There's probably nothing magical about the number itself.Filide
Hint for Arch Linux users: Systemd only applies settings from /etc/sysctl.d/*.conf. If you had customized /etc/sysctl.conf, you need to rename it as /etc/sysctl.d/99-sysctl.conf and do the work there!Acrilan
R
1

If you are looking for a workaround the idea is to use the version 4.x of NodeJS.

Remove NodeJS 5.x

sudo apt-get remove nodejs

Edit the sources list to enable node 4.x in the repo

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

Then in the file edit both two lines:

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

To

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

Update the repos again

sudo apt-get update

And reinstall node

sudo apt-get install -y nodejs

Check the versionm which should wrtite something like v4.3.1 or v4.x.x

node -v

Now you can run the angular quickstart with:

npm start

Hope it is useful.

EDIT:After installing the version 4.x of NodeJS

In the folder where you have your app:

$ rm -r node_modules

And then

npm install

Looks stupid, but when you run npm install it has to compile certain modules, and maybe (I do not know) the way of compiling them changes with the NodeJS versions.

Reclinate answered 21/2, 2016 at 19:2 Comment(2)
Unfortunately, this didn't work. I had previously tried this but tried it again to see if I missed something. Same problems, slightly different line numbers from the "stack trace".Raffinose
Seems obvious but, have you tried, after installing NodeJS v4.x, to remove the node_modules folder and install the modules again?Reclinate

© 2022 - 2024 — McMap. All rights reserved.