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

__dirname undefined #17

Open
y-nk opened this issue Sep 13, 2023 · 3 comments
Open

__dirname undefined #17

y-nk opened this issue Sep 13, 2023 · 3 comments

Comments

@y-nk
Copy link

y-nk commented Sep 13, 2023

when deploying on edge, __dirname is not defined, also it's said as a best practice to bundle all js in a single file to optimize cold start. hence, the code in here:

const DATA_DIR = path.join(path.dirname(__dirname), "data");

breaks execution of a lambda@edge using this package.

i was wondering if you had any suggestion for a suitable workaround?

@Doc999tor
Copy link

Doc999tor commented Sep 13, 2023

  1. Yes, you're right. For fixing it, you can use a workaround using path.dirname(url.fileURLToPath(import.meta.url)) - from here
  2. This repo is not maintained for a long time. If you don't build the MaxMind db in the @edge, you can use the fork, I actively maintain: https://github.com/Doc999tor/fast-geoip
  3. You can create a PR with __dirname fix to my repo, I'd be happy to let this great project evolve

@y-nk
Copy link
Author

y-nk commented Sep 14, 2023

@Doc999tor thanks for the fix provided, i will propose a PR with the fix you have mentioned.

meanwhile it gets accepted and merged, and to give a little context to visitors of this issue, since i'm using esbuild to pack my lambda@edge it can be solved without modifying the code by adding banner.js containing const __dirname = url.fileURLToPath(import.meta.url).

@y-nk
Copy link
Author

y-nk commented Sep 14, 2023

for people following this. for edge functions in aws, you don't need this package anymore since geoheaders come for free in cloudfront.

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

No branches or pull requests

2 participants