Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

npm crashes when running as a sub process of a Windows service on Windows XP #2840

Open
tellnes opened this Issue · 10 comments

9 participants

@tellnes
  C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:49
    var doExit = npm.config.get("_exit")
                            ^
  TypeError: Object #<Object> has no method 'get'
      at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js
  :49:27)
      at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\
  error-handler.js:264:3)
      at process.EventEmitter.emit (events.js:115:20)

node -v
v0.8.9

npm -v
1.1.61

@Crwth

I've just hit this as well (launching npm as a TeamCity Command Line Build Step.)

node -v
v0.8.11

npm -v
1.1.62

@tellnes

Sorry, looks like I was a little quick when I posted this issue. Here is the entire stacktrace.

Error: Failed to replace env in config: ${APPDATA}
    at C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\npmconf.js:329:13
    at String.replace (native)
    at envReplace (C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\npmconf.js:323:12)
    at parseField (C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\npmconf.js:302:7)
    at C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\npmconf.js:247:15
    at Array.forEach (native)
    at Conf.add (C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\npmconf.js:246:21)
    at ConfigChain.addString (C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\node_modules\config-chain\index.js:244:8)
    at Conf.addFile (C:\Program Files\nodejs\node_modules\npm\node_modules\npmconf\npmconf.js:235:10)
    at fs.readFile (fs.js:176:14)

C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:49
  var doExit = npm.config.get("_exit")
                          ^
TypeError: Object #<Object> has no method 'get'
    at exit (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:49:27)
    at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:264:3)
    at process.EventEmitter.emit (events.js:115:20)

The problem seems to be that when you are running a process as a service, you have not the APPDATA environment variable. It is solved easily either by defining it or by changing C:\Program Files\nodejs\node_modules\npm\npmrc.

@mpareja

+1 - We've seen this on a build machine running Windows Server 2003.

@dotSlashLu

+1 can't use npm through SSH with cygwin on win2009

@redfox25

i defined both env. variable
C:\Users\Administrator\AppData\Roaming;C:\Program Files\nodejs\node_modules\npm\npmrc and still have the issue described by tellnes. What else i might be missing?

@51mon
@redfox25

Thx!

@Ifnot

The APPDATA env variable is not defined on npm subprocess started by a service.

@51mon : APPDATA is not the folder of npm but a special folder given by windows for persistent data storage.

If you dont want to modify C:\Program Files (x86)\nodejs\node_modules\npm\npmrc (This file does not have a problem after all). Just set your APPDATA env variable into your subprocess like this :

var exec = require('child_process').exec;

exec('echo %APPDATA%', function (error, stdout, stderr) {
    process.env.APPDATA = stdout.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); // Trim the return with replaces

    // Here NPM execuction will work
});
@JamesKyburz

Had the same problem, and only needed to install packages locally so I did APPDATA=. npm install and that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.