geoip-lite / node-geoip

Native NodeJS implementation of MaxMind's GeoIP API -- works in node 0.6.3 and above, ask me about other versions
https://npmjs.org/package/geoip-lite
Other
2.32k stars 356 forks source link

Error: ENOENT: no such file or directory, open '/data/geoip-country.dat' using esbuild #220

Open CodeWithOz opened 3 years ago

CodeWithOz commented 3 years ago

I get the error Error: ENOENT: no such file or directory, open '/data/geoip-country.dat when using esbuild to generate a bundle for my nodejs app. There's already #195 but that was in a webpack setting, and I can't find an equivalent fix using esbuild. I've tried specifying the file loader (--loader:.dat=file) without any luck, and there appears to be no direct esbuild equivalent of the solution that was posted in #195 . Any ideas for how to resolve this problem?

sinclairzx81 commented 3 years ago

@CodeWithOz Just ran into this myself. You can get around this issue by marking geoip-lite as an external package. By setting this, esbuild won't try to bundle geoip-lite (keeping it inside node_modules), this means it can reference the data files in the expected location (and not referenced from your bundled output location)

More information on external can be found here https://esbuild.github.io/api/#external

DynamicRemo commented 2 years ago

in usual cases no additional parameter to config is required, no change of path to webpack is required, no setup as a plugin is required.

Try the basics to start with... clean up your node_module folder and run npm install. This happens rarely but dependencies when installed individually one after another during development could lead to such referencing issue. Cheers!

talkohavy commented 2 years ago

I got the same Error. I'm bundling with webpack. Can someone please provide a step-by-step as for how to solve this? I'm on the verge on giving up here....

LukeXF commented 1 year ago

I have the same issue, external doesn't work with esbuild

LukeXF commented 1 year ago

using etsc.config.js and adding this value fixed it:

    external: [
            'geoip-lite'
        ]
mkosir commented 1 year ago

For anyone coming to this (reoccurring) issue. Had same issue on Nextjs with version 1.4.7, downgraded to 1.4.6 and it works again.

bluesmoon commented 1 year ago

You can probably set the environment variable GEODATADIR to the path with your data files and it should work. That was the main change in 1.4.7

PascalPixel commented 10 months ago

Webpack can't resolve the paths to the .dat files automatically with NextJS, perhaps because the new global variable option GEODATADIR trips up the resolution, I don't know, but manually copying the .dat files worked for me;

const CopyWebpackPlugin = require("copy-webpack-plugin");

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.plugins.push(
        new CopyWebpackPlugin({
          patterns: [
            {
              from: "node_modules/geoip-lite/data/geoip-country.dat",
              to: "data/geoip-country.dat",
            },
            {
              from: "node_modules/geoip-lite/data/geoip-country6.dat",
              to: "data/geoip-country6.dat",
            },
          ],
        }),
      );
    }
    return config;
  },
};

module.exports = nextConfig;
hissincn commented 8 months ago

You can add flag like--external:geoip-lite such as"build": "npx esbuild server.ts --bundle --external:geoip-lite --platform=node --outfile=dist/index.js --minify" Bingo!