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

ENOENT: no such file or directory using geo-tz package #251

Closed
ErnestBrandi opened this issue Dec 17, 2021 · 10 comments · Fixed by #252
Closed

ENOENT: no such file or directory using geo-tz package #251

ErnestBrandi opened this issue Dec 17, 2021 · 10 comments · Fixed by #252
Labels
bug Something isn't working

Comments

@ErnestBrandi
Copy link
Contributor

ErnestBrandi commented Dec 17, 2021

Hi, I have Next.js website developed on Vercel and using the find method from the geo-tz package.
But once in production I get Error: ENOENT: no such file or directory, open '/var/task/node_modules/geo-tz/data/geo.dat'"}.
Seems like this package is to blame as when I build my project the file is not included in next-server.js.nft.json file.
If this is true, should it be treated as a "special-case" ?
Here the file where the error happens : https://github.com/evansiroky/node-geo-tz/blob/master/src/find.ts

@ErnestBrandi ErnestBrandi changed the title ENOENT: no such file or directory using geo-ts package ENOENT: no such file or directory using geo-tz package Dec 17, 2021
@styfle
Copy link
Member

styfle commented Dec 17, 2021

Sounds like a bug, thanks!

Can you share the usage that causes it to fail?

I tried the following but it worked as expected:

const { find } = require('geo-tz');
console.log(find(47.650499, -122.350070))

Here's how it can be tested against nft:

npm i -g @vercel/nft
mkdir example
cd example
npm init -y
npm install geo-tz
echo "const { find } = require('geo-tz'); console.log(find(47.650499, -122.350070))" > index.js
nft build
rm -rf node_modules
node dist/index.js

@styfle styfle added the bug Something isn't working label Dec 17, 2021
@ErnestBrandi
Copy link
Contributor Author

I'm not sure what's going on. Following your example I started playing with the nft command line and when I do nft print lib/**/* | grep geo-tz, I can see node_modules/geo-tz/data/geo.dat is listed.
But again when I build my project (even locally) using next build I cannot see that file listed in the next-server.js.nft.json file (I am using next 12.0.7).

@styfle
Copy link
Member

styfle commented Dec 19, 2021

That could be because **/* glob is expanded so its going to check every file but perhaps there is a path that is not finding geo.dat when it should.

It would be helpful if you could share the source code that is failing

@ErnestBrandi
Copy link
Contributor Author

ErnestBrandi commented Dec 19, 2021

EDIT : actually there is already an issue about this problem on geo-tz side (evansiroky/node-geo-tz#111). Apparently it comes from bad transpiling resulting in the file not being included and it only happens for certain coordinates (for instance : -21.2377437, 55.48997639438238).

@ErnestBrandi
Copy link
Contributor Author

I think treating geo-tz library as a special case would solve the problem :

'geo-tz'({ id, emitAsset }) {
     if (id.endsWith('geo-tz/dist/geo-tz.js')) {
         emitAsset(path_1.resolve(path_1.dirname(id), '../data/geo.dat'));
     }
},

@styfle
Copy link
Member

styfle commented Dec 20, 2021

Yes that should work, but I want to add an integration test so we don't regress and hopefully be able to fix it properly in the future.

So we need to create the failing example. And when I tried this, it doesn't fail:

const { find } = require('geo-tz');
console.log(find(47.650499, -122.350070))

@ErnestBrandi
Copy link
Contributor Author

Yep, but as I said it only happens for certain coordinates (as the ones in my previous post, also here is a repro project : https://gitlab.com/leotellier/nft-geotz/-/blob/main/pages/api/geo.js). Be sure to check the last comment (from project owner) in the linked issue on geo-tz, it might help you understanding what's going on.

@styfle
Copy link
Member

styfle commented Dec 20, 2021

Oh I missed that part, thanks!

I see now this code fails:

const { find } = require('geo-tz');
console.log(find(-21.2377437, 55.48997639438238))

My guess is that the dist/geo-tz.js is mangled and breaks that static analysis.

We have some analysis for these cases in wrappers.ts so if we can determine the bundler and the pattern used, we can probably have a more general fix there.

Otherwise the quick fix is special-cases.ts like you suggested.

@ErnestBrandi
Copy link
Contributor Author

ErnestBrandi commented Dec 20, 2021

The wrapper method is beyond my skills and knowledge but I can open a PR for the special-cases method if you want to.

@styfle
Copy link
Member

styfle commented Dec 20, 2021

Ok lets start with special cases and add an integration test to ensure its working 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants