bull-board icon indicating copy to clipboard operation
bull-board copied to clipboard

Next.js & Vercel Support

Open caseypugh opened this issue 2 years ago • 23 comments

There's an ongoing thread #124 here about how to integrate bull-board/express with Nextjs. The latest solution works great, however, if you are deploying to Vercel you run into issues trying to access @bull-board/ui/package.json.

Here's the main issue, I believe

const uiBasePath = path.dirname(eval(`require.resolve('@bull-board/ui/package.json')`));

Vercel is not going to give access to the full path of their server... so pretty sure relative paths need to be used instead. Something like...

  const uiBasePath = "node_modules/@bull-board/ui"
  serverAdapter
    .setQueues(bullBoardQueues)
    .setViewsPath(uiBasePath + 'dist')
    .setStaticPath('/static', uiBasePath + 'dist/static')    

Also, it'd be great to see official Nextjs support in the documentation.

caseypugh avatar Aug 23 '22 15:08 caseypugh

How Vercel suggest to work with paths? The code you've mentioned is correct by Node, so if there is some restrictions in Vercel the solution should come from them.

Btw, the code fixes #310

felixmosh avatar Aug 23 '22 16:08 felixmosh

I'm pretty sure generally all you need to do is specify the relative paths which should work for everyone, but I could be wrong. @felixmosh whats the best way to test & pull in my forked changes into my repo?

caseypugh avatar Aug 23 '22 17:08 caseypugh

You can install from github from you branch...

felixmosh avatar Aug 23 '22 17:08 felixmosh

+1, I'm getting the same error on Vercel:

Error: Cannot find module '@bull-board/ui/package.json'
Require stack:
- /var/task/node_modules/@bull-board/api/dist/src/index.js
- /var/task/apps/platform/.next/server/pages/api/queues/[[...path]].js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/apps/platform/___next_launcher.cjs
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at eval (eval at createBullBoard (/var/task/node_modules/@bull-board/api/dist/src/index.js:13:47), <anonymous>:1:9)
    at createBullBoard (/var/task/node_modules/@bull-board/api/dist/src/index.js:13:47)
    at /var/task/apps/platform/.next/server/pages/api/queues/[[...path]].js:88:65 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/var/task/node_modules/@bull-board/api/dist/src/index.js',
    '/var/task/apps/platform/.next/server/pages/api/queues/[[...path]].js',
    '/var/task/node_modules/next/dist/server/next-server.js',
    '/var/task/apps/platform/___next_launcher.cjs'
  ]
}

samuelcole avatar Sep 02 '22 17:09 samuelcole

Any suggestions how to fix this?

felixmosh avatar Sep 02 '22 18:09 felixmosh

@felixmosh @samuelcole I have a fork where I have been testing a potential fix. I'm using yarn link locally to test the change and it works great, but I'm not sure how to go about testing on Vercel.

AFAIK, I can't simply just point my package.json to my fork, because it doesnt contain any of the compiled builds that get published on npm. Any suggestions / best practices on how to go about testing on production?

caseypugh avatar Sep 05 '22 18:09 caseypugh

You can point to your fork with a branch, which there will push the dist.

felixmosh avatar Sep 05 '22 18:09 felixmosh

any update on this? i'm ridiculously running bull-board on my local computer with my production redis url to work around this 😬

samuelcole avatar Oct 04 '22 19:10 samuelcole

@samuelcole did you debug the issue? I'm not familiar with Vercel at all...

felixmosh avatar Oct 04 '22 20:10 felixmosh

i'm not sure how to deploy @caseypugh's branch to vercel

my package.json has

"@bull-board/express":` "^4.3.2",

can i just point that to casey's github url?

samuelcole avatar Oct 04 '22 20:10 samuelcole

@samuelcole you can technically do:

"@bull-board/express": "caseypugh/bull-board",

but it wont work. my dumb hack around this has been to separately deploy a vanilla Bull Dashboard to Heroku (no nextjs). I put a queues folder in my nextjs monorepo and then added these extra commands to my package.json for deploying the dashboard (and workers).

{
  ...
  "build": "yarn queue-build",
  "queue-build": "npx tsc --esModuleInterop true --outDir .build/ queues/*.ts",
  "dev:worker": "npx nodemon queues/process.ts",
  "dev:dashboard": "npx nodemon queues/dashboard.ts",
  "dashboard": "node .build/queues/dashboard.js",
  "worker": "node .build/queues/process.js",
}

@felixmosh There is no easy way (that I know of) for us to point the package.json to my fork because there are no committed dist/ folders in the repo. I'd have to publish my fork to npm just to test a simple change. I think? How do you test changes on a cloud provider without publishing to npm?

What if I set up a sample Nextjs project for you and then you could try deploying to Vercel yourself to see the issue directly? It's entirely free. Also, Vercel wont be the only cloud provider that has this issue. The fact you are using full system paths is a code smell since a cloud provider would never give you access to the fullpath due to security concerns. You'd need to use relative paths.

caseypugh avatar Oct 05 '22 03:10 caseypugh

@caseypugh how can we solve this? make the paths relative? How can I debug this issue myself?

felixmosh avatar Dec 14 '22 18:12 felixmosh

@felixmosh Easiest thing to do is to sign up for a serverless provider like Vercel and try deploying a sample project yourself. It's 100% free!

And yes, like I said before, I'm pretty sure the solution is to just make the paths relative.

caseypugh avatar Dec 15 '22 14:12 caseypugh

@caseypugh but I don't have a public redis service that I can connect to in order to test it....

felixmosh avatar Jan 12 '23 10:01 felixmosh

Can someone try with the mentioned solution here? https://github.com/felixmosh/bull-board/issues/485#issuecomment-1414339022

felixmosh avatar Feb 02 '23 20:02 felixmosh

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 03 '23 23:05 stale[bot]

Keeping it alive: still a problem for me

samuelcole avatar May 04 '23 03:05 samuelcole

The same here, looking forward for a fix

Uchihinha avatar May 17 '23 02:05 Uchihinha

@Uchihinha try this: https://github.com/felixmosh/bull-board/issues/485#issuecomment-1549146066

samuelcole avatar May 17 '23 02:05 samuelcole

@samuelcole it worked now, thank you!

Uchihinha avatar May 17 '23 02:05 Uchihinha

The issue isn't with vercel's hosting, it's their build step that uses (or operates similarly to) @vercel/ncc. The files don't exist because they aren't referenced, and are stripped from the production build. I'm using ncc for an express deployment, and encountered the same error message.

mckernanin avatar Nov 19 '23 06:11 mckernanin

For those like me struggling to make it work, I got it working now, thanks to https://github.com/felixmosh/bull-board/issues/485#issuecomment-1549146066 + https://github.com/felixmosh/bull-board/issues/485#issuecomment-1555673004 🎉

this is my full vercel.json file:

{
  "version": 2,
  "rewrites": [
    {
      "source": "/admin/queues",
      "destination": "api/server.js"
    },
    {
      "source": "/admin/queues/(.*)",
      "destination": "api/server.js"
    }
  ],
  "functions": {
    "api/server.js": {
      "includeFiles": "node_modules/@bull-board/ui/**"
    }
  }
}

and this is my createBullBoard call:

createBullBoard({
  queues,
  serverAdapter: serverAdapter,
  options: { uiBasePath: `${process.cwd()}/node_modules/@bull-board/ui` },
});

rogeriochaves avatar Feb 14 '24 17:02 rogeriochaves

This issue also affects esbuild bundling. I'm trying it for fastify, but it's not working.

Eyon42 avatar Feb 19 '24 23:02 Eyon42