Closed benjosua closed 2 weeks ago
As shown in this comment, I did this as well, and it solved the problem.
This is the code that should be in next.config.mjs
:
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
reactStrictMode: true,
experimental: {
serverComponentsExternalPackages: ["geoip-lite"],
},
};
export default nextConfig;
Still, it’s a problem why Next.js doesn't display an error and instead returns a 404.
@moshefortgang Thank you very much for this solution. It indeed fixes the issue. I agree that it's problematic that Next.js doesn't display an error and instead returns a 404 in this situation.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Link to the code that reproduces this issue
https://github.com/benjosua/geoip-lite-next-issue
To Reproduce
When importing
geoip-lite
in a Next.js 14 App Router route handler, the route returns a 404 error.Reproduction Steps
geoip-lite
:pnpm install geoip-lite
File:
/app/api/working-example/route.ts
File:
/app/api/error-example/route.ts
http://localhost:3000/api/working-example
- This works as expectedhttp://localhost:3000/api/error-example
- This returns a 404 errorCurrent vs. Expected behavior
Expected Behavior
Both routes should return a JSON response with
{ message: 'Test' }
.Actual Behavior
The route importing
geoip-lite
returns a 404 error.Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response