node-app-root-path icon indicating copy to clipboard operation
node-app-root-path copied to clipboard

feat: stop using `__dirname` if `APP_ROOT_PATH` is defined

Open IslamWahid opened this issue 3 years ago • 2 comments

  • 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.

IslamWahid avatar Sep 22 '22 14:09 IslamWahid

@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

IslamWahid avatar Sep 22 '22 15:09 IslamWahid

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);

GoodbyeNJN avatar Oct 13 '22 09:10 GoodbyeNJN