Comments (4)
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.
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.
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.
@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)
- Fail gracefully in unsupported browsers HOT 15
- Drop eval usage HOT 21
- line info is not help HOT 8
- Cannot redefine property: callSiteToString HOT 2
- Call-site calculation does not fail gracefully when Stack information is unavailable HOT 14
- Call site calculation fails when importing an esm'ed package that imports sequelize internally HOT 14
- Respect --no-deprecation and process.noDeprecation HOT 17
- TypeError: eval is not a function HOT 8
- Why is this library overwriting Error type? HOT 5
- Turkish Language Problem HOT 2
- Incopatibile with --enable-source-maps node 12 option HOT 7
- (!) Use of eval is strongly discouraged, rollup HOT 1
- compatibility with Node.js' source-map implementation HOT 12
- please rewrite nodejs-depd with modern syntax HOT 1
- Compatibility with --disallow-code-generation-from-strings HOT 9
- Use of eval() is strongly discouraged, as it poses security risks HOT 9
- callSite.getFileName() is not Function HOT 5
- `callSite.getFileName` is not a function HOT 10
- NodeJS 20.11.0 fails when building snapshot.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-depd.