BUG: Missing file from node_module

Somehow files are missing from node_modules in the Deployment

When hosting my application on vercel, visiting anything under /journey/ produces the following error:

Uncaught Exception: [Error: ENOENT: no such file or directory, open '/vercel/path0/node_modules/db-hafas-stations/full.ndjson'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/vercel/path0/node_modules/db-hafas-stations/full.ndjson'
}

This only happens on vercel. It referrrs to a submodule of db-vendo-client which is a library my code uses.
Here is the relevant lines (src/components/journey/StopsContainer.tsx):

 useEffect(() => {
    if (!risId) return;
    async function fetchJourney() {
      setVendoLoading(true);
      const vendoData = JSON.parse(await getVendoJourney(risId));
      if (!vendoData) {
        setVendoLoading(false);
        return;
      }

      setStopsWithVendo((prev) =>
        prev.map((stop) => {
          const vendoStop = vendoData.stopovers?.find(
            (vendoStop: any) => vendoStop.stop?.id === stop.station.evaNo
          );
          if (!vendoStop) return stop;
          return {
            ...stop,
            loadFactor: vendoStop.loadFactor,
          };
        })
      );
      setVendoLoading(false);
    }
    fetchJourney();
  }, [risId]);
    "build": "next build && ls node_modules/db-hafas-stations/",

I have added a ls statement to the build command to output the contents of said module.
This however outputs the following:

[11:18:59.304] data.ndjson
[11:18:59.305] full.ndjson
[11:18:59.305] index.js
[11:18:59.305] license-data.md
[11:18:59.305] license.md
[11:18:59.305] package.json
[11:18:59.306] readme.md

I have no clue what is happening. All modules are installed correctly. No errors during build process or on any other pages. Thank you in advance

GitHub source
Page producing the error

Hey, @crwntec!

I’m unable to see the error on the page. It actually looks like it’s running smoothly! Could you share you changed?

Sorry. The error is only visible in the logs. Client wise you can see that the loading doesn’t finish for the occupancy. The loading spinners next to the stop names should finish loading and display an icon. However if you look in the browser console you can see that request failing because of the error above

This is the link to the screenshot btw

Hey @crwntec,

I recently ran into the exact same issue when deploying my app that uses db-vendo-client, which in turn depends on db-hafas-stations. Since GitHub imposes a 100 MB file size limit and Vercel’s free plan has a 50 MB limit for serverless function bundles, my suspicion was that Vercel silently skipped the large full.ndjson (~119 MB) file during install — and then failed when trying to access it at runtime.

To work around this, I extracted the data from full.ndjson and imported it into my own PostgreSQL table. I then modified the db-vendo-client code to query my database instead of reading from the file via db-hafas-stations. That resolved the issue for me. :blush:

Hope that helps!

1 Like

Well this could be a potential explanation. But wouldn’t this trigger a build error? I’ve seen these „function exceeds size limit“ before online but not in my application. And my post install scripts outputs a listing of the modules directory that somehow contains the file? I mean your fix sounds like a good workaround but where is this coming from?

1 Like

I’m having the same issue, but with a library without external dependencies. More specifically, I am using Zod to create and validate configuration schemas, and I’m using a simple import map to pinpoint it in my node_modules folder (due to my TS configuration). No matter what I do, trying to utilise or access anything inside node_modules/zod returns with the same exact behaviour mentioned on your end. Locally, everything works fine, but not at all on Vercel. Zod also has a bundled size of 5-7kb, so I’m not sure if the size would also be an issue, unless I’ve misunderstood. Building and lsing shows a perfect installation, to no avail. I have a mono-repo but duo-deployment setup for both my frontend and backend, and this issue is only present with Zod in the frontend.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Hi everybody,

I am running into the same error that is being described in this previous post: BUG: Missing file from node_module

I have tried building npm run build and running locally npm run start using the default nextjs scripts. Everything works fine locally, but when I try to hit an endpoint on production (deployed via vercel), I get the following error:

[Error: ENOENT: no such file or directory, open 'node_modules/kuromoji/dict/base.dat.gz'] {
errno: -2,
code: 'ENOENT',

I noticed that the original discussion thread was closed due to inactivity, but hoping to get some help regarding this issue.

Hi, @thecalvinchan!

I just moved this to the original thread to keep discussions in one place.

Do you have a minimal reproducible example we can take a look at?

I recommend checking out this thread:

Thanks @pawlean .

Sure, I am trying to use the Kuroshiro libraries to provide ruby text to japanese characters.

Here’s my lib file

// @ts-expect-error Kuroshiro is not typed
import KuromojiAnalyzer from "kuroshiro-analyzer-kuromoji"
// @ts-expect-error Kuroshiro is not typed
import Kuroshiro from "kuroshiro-enhance"

// Instantiate
const kuroshiro = async () => {
  let _kuroshiro: Kuroshiro | null = null
  if (!_kuroshiro) {
    _kuroshiro = new Kuroshiro()
    await _kuroshiro.init(new KuromojiAnalyzer())
  }
  return _kuroshiro
}

export default kuroshiro

And it’s being used in my route file like so

  if (includePronunciation && output_target_language) {
    const kuroshiroInstance = await kuroshiro()
    const furigana = await kuroshiroInstance.convert(output_target_language, {
      to: targetSyllabary,
      mode: "furigana"
    })
    output_furigana = furigana
  }

In this example, kuromoji is a dependency of kuroshiro-analyzer-kuromoji. This is working completely fine on my local computer (i have tested npm run build and npm start), but for some reason, vercel is unable to find the dictionaries provided by kuromoji.