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

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

Open
CodeWithOz opened this issue Jun 15, 2021 · 9 comments

Comments

@CodeWithOz
Copy link

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

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

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

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

LukeXF commented Oct 23, 2022

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

@LukeXF
Copy link

LukeXF commented Oct 23, 2022

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

	external: [
			'geoip-lite'
		]

@mkosir
Copy link

mkosir commented Feb 10, 2023

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

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

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

hissincn commented Jan 3, 2024

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!

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

9 participants