-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling process.cwd()
from index.js can be problematic
#45
Comments
Hm, that is an interesting scenario. Unfortunately |
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? |
Steps to reproduce:Create a project directory
Install dependencies,
Make another directory, and cd into it. It doesn't particularly matter where.
Not from another terminal, remove the directory you created.
Now from the original terminal use the absolute path to invoke issue_45.js.
If you happen to be executing TypeScript bundled with webpack, the error message is not as friendly, it doesn't mention 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. |
@dougwilson would there be any negative consequences to wrapping Something like this:
|
The following line in index.js can crash some node apps.
var basePath = process.cwd()
This line in index.js is problematic for some node applications that might get invoked from a directory that has been removed by another process.
The application may not actually need the current working directory, but it never gets a chance to run because node barfs if
depd
is a dependency of anything pulled in with arequires
statement.I haven't looked into why you need this, but maybe
__filename
or__dirname
would be more appropriate here? Since it would be hard to execute a node app that didn't exist.The text was updated successfully, but these errors were encountered: