xDimGG / node-steamapi

An object-oriented Steam API wrapper for Node.js developers.
https://www.npmjs.com/package/steamapi
181 stars 42 forks source link

Error: Cannot find module '../../package.json' #55

Open twbrianho opened 3 months ago

twbrianho commented 3 months ago

Hi! Sorry, it's me again.

Problem

The build step runs fine, but now I'm seeing a new runtime error:

Error: Cannot find module '../../package.json'
Require stack:
- /vercel/path0/node_modules/steamapi/dist/src/SteamAPI.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at /var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:11:28979
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at /opt/rust/nodejs.js:1:11508
    at Function.Wt (/opt/rust/nodejs.js:1:11878)
    at Q.e.<computed>.K._load (/opt/rust/nodejs.js:1:11478)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at u.require (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:11:29195)
    at require (node:internal/modules/helpers:179:18)
    at 8414 (/var/task/.next/server/app/api/trpc/[trpc]/route.js:8:41752) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/vercel/path0/node_modules/steamapi/dist/src/SteamAPI.js' ],
  page: '/api/trpc/steam.getGameDetails'
}

This only happens on Vercel, not locally. Any clue what might be causing this?

Context

I'm using SteamAPI inside tRPC pretty normally:

import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { env } from "~/env";
import SteamAPI from "steamapi";

export const steamRouter = createTRPCRouter({
  getGameDetails: publicProcedure
    .input(z.object({ appId: z.number() }))
    .query(async ({ input }) => {
      const steam = new SteamAPI(env.STEAM_API_KEY);
      return await steam.getGameDetails(input.appId);
    }),
});

The above error occurs when I try to call the getGameDetails endpoint, which is under /api/trpc/steam.getGameDetails.

Thanks again for your help and speedy responses :)

xDimGG commented 3 months ago

Hmm I'm not familiar with Vercel so I'm not sure how that environment would affect imports. Would it be possible for you to join the Discord server and we can chat or you can screen share so I can try to debug? https://discord.gg/z9thk2jX

patrickwcode commented 2 months ago

@twbrianho I don't know if this error is still an issue. Does this post on Stack Overflow help?

twbrianho commented 2 months ago

I think that may be a different issue. My build finishes successfully, this error happens at runtime on the server side.