Skip to content
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

feat: stop using __dirname if APP_ROOT_PATH is defined #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IslamWahid
Copy link

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

- 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
Copy link
Author

@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 IslamWahid changed the title fix: stop using __dirname if APP_ROOT_PATH is set fix: stop using __dirname if APP_ROOT_PATH is defined Sep 22, 2022
@IslamWahid IslamWahid changed the title fix: stop using __dirname if APP_ROOT_PATH is defined feat: stop using __dirname if APP_ROOT_PATH is defined Sep 22, 2022
@GoodbyeNJN
Copy link

GoodbyeNJN commented Oct 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants