Next.js Discord

Discord Forum

I am facing error when deploying on vercel

Answered
Cape lion posted this in #help-forum
Open in Discord
Avatar
Cape lionOP
Error: ENOENT: no such file or directory, open '/vercel/path0/.next/server/chunks/DB/20151116/GeoLite2-City.mmdb'

at m.openSync (/vercel/path0/.next/server/chunks/217.js:1:94726)
at d.openSync (/vercel/path0/.next/server/chunks/217.js:1:87115)
at i.init (/vercel/path0/.next/server/chunks/217.js:1:96623)
at new i (/vercel/path0/.next/server/chunks/217.js:1:96578)
at 27641 (/vercel/path0/.next/server/chunks/217.js:1:97083)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:143)
at 48730 (/vercel/path0/.next/server/app/api/auth/forget-password/route.js:1:5841)
at t (/vercel/path0/.next/server/webpack-runtime.js:1:143) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/vercel/path0/.next/server/chunks/DB/20151116/GeoLite2-City.mmdb'
}
Answered by Anay-208
Summary:
- The issue was caused due to the fact that a package was reading a file
- That file needs to be added in vercel.json
View full answer

15 Replies

Avatar
Cape lionOP
@Anay-208

My route seems correct but idk why it throwing error in production for file not found
Image
Image
I have no clue about where the error is comming in forget-password route

import { NextRequest, NextResponse } from "next/server";
import User from "@/models/User";
import connectDB from "@/db";
import bcryptjs from 'bcryptjs';
import { forgotPasswordValidation } from "@/validations/User";
import { createTokenPayload, signAccessToken, signInfoToken } from "@/utils/auth";
import { ClientDetailsType, getClientIPInfo, IPInfoType } from "@/utils/UserTracking";
import { v4 as uuidv4 } from 'uuid';
import SessionModel from "@/models/Session";


export async function POST(req: NextRequest) {
    try {

        await connectDB();

        const data = await req.json();

        const { email, otp, password, confirmPassword } = data;

        const { error } = forgotPasswordValidation.validate({ email, otp, password, confirmPassword });

        if (error) return NextResponse.json({ success: false, message: error.details[0].message.replace(/['"]+/g, '') });

        const findUser = await User.findOne({ email });

        if (!findUser) return NextResponse.json({ success: false, message: 'Account Not Found' });

        som more code ....
a
    } catch (error: any) {

        console.log("Error in Resetting User Password (Server) => ", error.message)

        return NextResponse.json({ success: false, message: "oopss ! Something went wrong..." });
    }
}
Avatar
are you using fs or reading any file?
Avatar
Cape lionOP
in the backend no I just have an auth system yet
Avatar
Are upi readomg any file, because if I'm right, its attempting to read GeoLite2-City.rmdb
Avatar
Cape lionOP
alright then i think some packages code , i am using these to track the user based on ip etc for session
import { NextRequest } from "next/server";
import DeviceDetector from 'device-detector-js';
import UAParser from 'ua-parser-js';

// @ts-ignore
import satelize from "satelize";
and yes 1 thing i remember is that satelize doesn't have ts type so i tried to use ignore to get rid of that
these are the pakcages that is in use in auth/forget-password cuz i am creating a new session there
Avatar
Cape lionOP
got it

the problem is indeed with pakakage as now i installed
https://www.npmjs.com/package/geoip-lite

and error file name change to geoip-country.dat
Image
Avatar
you can try to use this in vercel.json, to that file path. I'm unsure if it would work:
    "functions": {
        "funcName/*": {
            "includeFiles": "path/to/file"
        }
    }
Avatar
Cape lionOP
i am unsure about that file to, cuz i don't have to provide that file , package imports and it should have come with pakcage

actaully these thing was working fine on my node js app that i deploy on beanstalk so i am clueless now about the file , let see at least now i know who is creating an error i'll try to find other packages or ways

function actually return me country code lat- long and timezone etc

// Define an interface for the IP Info response
export interface IPInfoType {
    country: string;
    timezone: string;
    country_code: string;
    lat_long: string;
}

// Function to get client IP info based on IP address
export const getClientIPInfo = async (ip: string): Promise<IPInfoType | null> => {
    try {
        // Get geolocation information from geoip-lite
        const geo = geoip.lookup(ip);

        // Declare the variables to store user details with initial values
        let country = "Unknown";
        let timezone = "Unknown";
        let country_code = "Unknown";
        let lat_long = "Unknown";

        if (geo) {
            country = geo.country || "Unknown";
            timezone = geo.timezone || "Unknown"; // Get timezone directly from geo
            country_code = geo.country || "Unknown"; // Assuming country code is the same as country
            lat_long = geo.ll ? `${geo.ll[0]}, ${geo.ll[1]}` : "Unknown"; // Format lat and long
        }

        // Return the populated IP info object
        return { country, timezone, country_code, lat_long };

    } catch (error) {
        console.error('Error in getClientIPInfo (clientIPInfo.js) =>', (error as Error).message);
        return null;
    }
};
i try to find any other if possible to find these thing without pakcage
Avatar
Summary:
- The issue was caused due to the fact that a package was reading a file
- That file needs to be added in vercel.json
Answer
Avatar
Mark solution please if the issue is resolved