Giter Club home page Giter Club logo

Comments (4)

dougwilson avatar dougwilson commented on July 4, 2024

Hm, that is an interesting scenario. Unfortunately __filename and __dirname don't work for the use case, as those of course represent very different locations and are not interchangeable.

from nodejs-depd.

dougwilson avatar dougwilson commented on July 4, 2024

Regardless we can work around this issue. I assume that by crash you mean that it throws an error? Do you happen to have the specific error it throws on hand you can paste here?

from nodejs-depd.

ohz10 avatar ohz10 commented on July 4, 2024

Steps to reproduce:

Create a project directory issue_45 and a package.json in it.

// package.json
{
  "name": "test",
  "version": "0.0.1",
  "description": "demonstrate depd issue 45",
  "license": "Public Domain",
  "dependencies": {
    "depd": "~1.1.2"
  }
}

Install dependencies, $ npm install -save

// issue_45.js
var depd = require('depd');
console.log('issue 45');

Make another directory, and cd into it. It doesn't particularly matter where.

$ mkdir test && cd test

Not from another terminal, remove the directory you created.

$ rmdir test

Now from the original terminal use the absolute path to invoke issue_45.js.

$ node /Users/<user>/issue_45/issue_45.js

$ node /Users/<user>/issue_45/issue_45.js
internal/bootstrap/switches/does_own_process_state.js:130
    cachedCwd = rawMethods.cwd();
                           ^

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:130:28)
    at Object.<anonymous> (/Users/<user>/issue_45/node_modules/depd/index.js:25:24)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/Users/<user>/issue_45/issue_45.js:1:12)
    at Module._compile (internal/modules/cjs/loader.js:1072:14) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

If you happen to be executing TypeScript bundled with webpack, the error message is not as friendly, it doesn't mention depd in the call stack, but you get the same error message.

You might be wondering how this could possibly happen. We've bundled a web service and some CLI tools for managing it into a single pack, and the CLI is installed in /opt/local/bin/. Some directories that hold state for the web service get deleted when some components are reconfigured & a customer was poking around the filesystem during a restart & happened to invoked the CLI tool from a deleted directory.

from nodejs-depd.

ohz10 avatar ohz10 commented on July 4, 2024

@dougwilson would there be any negative consequences to wrapping process.cwd() in a try/catch block and setting it to undefined or null on error?

Something like this:

function tryCwd() {
  try {
    return process.cwd();
  } catch(e) {
    return undefined;
  }
}

var basePath = tryCwd()

from nodejs-depd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.