node-app-root-path
node-app-root-path copied to clipboard
feat: stop using `__dirname` if `APP_ROOT_PATH` is defined
- it is not necessary to use __dirname if APP_ROOT_PATH env var is used.
- this should solve a problem when the package is used in an ESM app.
@inxilpro could you please have a look. I've a problem using typeorm which is using your package internally so when I build my app as esm I get an error
Runtime.UnhandledPromiseRejection: ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and
Same issue for me, but return to normal after replacing __dirname.
Suggestion: Is it better to change it like this?
var dirname = '';
try {
dirname= __dirname
} catch {
dirname = process.env.APP_ROOT_PATH;
}
var lib = require('./lib/app-root-path.js');
module.exports = lib(dirname);