inxilpro / node-app-root-path

Determine the root path to your project
MIT License
605 stars 29 forks source link

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

Open IslamWahid opened 1 year ago

IslamWahid commented 1 year ago
IslamWahid commented 1 year ago

@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
GoodbyeNJN commented 1 year ago

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