Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Npm scripts set TMPDIR environment variable #4531

@kumavis

Description

@kumavis

I found this bug while using os.tmpdir()

When executing as root on OSX, there is no explicit tmpdir provided from the environment variables. When using os.tmpdir(), node correctly falls back to '/tmp'. However when running scripts via npm, it seems that the environment variable TMPDIR is set to the cwd when undefined. This causes os.tmpdir() to incorrectly return the cwd as the tmp directory.

in my package.json

"scripts": {
    "test": "echo $TMPDIR"
  },
npm test
#=> correct temp dir
sudo npm test
#=> current working directory (??)
node -e "console.log(process.env.TMPDIR)"
#=> correct temp dir
sudo node -e "console.log(process.env.TMPDIR)"
#=> undefined

another test, in my package.json

"scripts": {
    "test": "node -e \"console.log(require('os').tmpdir())\""
  },
npm test
#=> correct temp dir
sudo npm test
#=> current working directory (??)
node -e "console.log(require('os').tmpdir())"
#=> correct temp dir
sudo node -e "console.log(require('os').tmpdir())"
#=> '/tmp'

my system (osx 10.9.1):

node -v
#=> v0.10.22
npm -v
#=> 1.3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions