Open CodeWithOz opened 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
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!
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....
I have the same issue, external doesn't work with esbuild
using etsc.config.js
and adding this value fixed it:
external: [
'geoip-lite'
]
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.
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
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;
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!
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 thefile
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?