frog icon indicating copy to clipboard operation
frog copied to clipboard

Importing files doesn't work on Vercel deployment

Open RareSecond opened this issue 1 year ago • 14 comments

I created a minimal reproducible example.

This repository was started by running bunx create-frog -t vercel. Then the only change I did was extract the actual rendering of the frame into a separate file.

This all works fine when running bun run dev locally.

image

However, after deploying to Vercel (by running bun run deploy), the serverless function is crashing.

This is the full error log from Vercel

Error: Cannot find module '/var/task/api/Frame.js' imported from /var/task/api/index.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:332:11)
    at moduleResolve (node:internal/modules/esm/resolve:1029:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:876:12)
    at defaultResolve (node:internal/modules/esm/resolve:1242:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36) {
  url: 'file:///var/task/api/Frame.js',
  code: 'ERR_MODULE_NOT_FOUND'
}
INIT_REPORT Init Duration: 284.92 ms	Phase: init	Status: error	Error Type: Runtime.ExitError
Error: Cannot find module '/var/task/api/Frame.js' imported from /var/task/api/index.js
    at new NodeError (node:internal/errors:405:5)
    at finalizeResolution (node:internal/modules/esm/resolve:332:11)
    at moduleResolve (node:internal/modules/esm/resolve:1029:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:876:12)
    at defaultResolve (node:internal/modules/esm/resolve:1242:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:403:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:372:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36) {
  url: 'file:///var/task/api/Frame.js',
  code: 'ERR_MODULE_NOT_FOUND'
}
INIT_REPORT Init Duration: 359.00 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1

RareSecond avatar Feb 29 '24 19:02 RareSecond

Hmm, seems like Vercel Build CLI has trouble importing JSX files. Taking a look.

jxom avatar Feb 29 '24 22:02 jxom

So I stumbled upon this issue on the Vercel GH and contacted Vercel support with the details from this repro.

CleanShot 2024-03-01 at 16 04 15

I'll try to see what exactly they know is going wrong and if there are ways around it!

RareSecond avatar Mar 01 '24 15:03 RareSecond

We could probably transpile the JSX files before the vercel build step. Can take a look into it.

jxom avatar Mar 02 '24 05:03 jxom

We are having the same issue. Are there any updates here?

andypavia avatar Mar 13 '24 18:03 andypavia

Hey guys! Hitting the same issue. It's really annoying & hard to maintain everything in a single jsx api file. Do you have any new information on this issue?

Should we just ditch the vercel template and try to migrate to a nextjs one? Would hate to do that as I find the vercel one a lot easier to debug.

ealeksandrov7 avatar Mar 15 '24 11:03 ealeksandrov7

We deployed our project through Vercel by putting everything into one file. Horrible and hard to maintain...

Some people were able to deploy through Cloudflare workers. We weren't able to since Neynar uses Axios, and Cloudflare doesn't support Axios for some reason.

andypavia avatar Mar 15 '24 11:03 andypavia

@RareSecond, in your reproducible example, there is a circular dependency issue. index.tsx depends on Frame.tsx and vice-versa.

For everyone having a pain of maintaining everything in a single file, there is a .route method that allows you to join multiple frogs in one.

https://github.com/wevm/frog/blob/21dff589992e464ab11b7924b7c559e2a1e160e0/playground/src/index.tsx#L180-L187

That's definitely something that has to be put in the docs.

dalechyn avatar Apr 05 '24 12:04 dalechyn

Tried different approaches myself, can't fix.

Found a small improvement opportunity though: https://github.com/wevm/frog/pull/258

dalechyn avatar Apr 14 '24 16:04 dalechyn

Any updates on this? Wondering if theres at least a work around that's not "put everything into a single file"

blaynem avatar Apr 19 '24 07:04 blaynem

Also hitting this 🙋🏽‍♂️

colinnielsen avatar Apr 24 '24 01:04 colinnielsen

This bug is a huge bummer. Jamming components into the main index file isn't sustainable. Is the answer to simply migrate away from Vercel?

rforte avatar Jul 17 '24 14:07 rforte

Jumping in here to see if there's any update on this. My frame is getting relatively complex and difficult to manage from a single file.

99darwin avatar Jul 19 '24 13:07 99darwin

I'll make another push on this this weekend.

From my previous attempt I remember there was a limitation on Vercel side, that generally Serverless API handlers could not import other modules.

dalechyn avatar Jul 19 '24 13:07 dalechyn

I'm importing modules into my api/index.tsx file just fine. It's when the imported module contains JSX. It appears that those modules get stripped out entirely.

rforte avatar Jul 19 '24 13:07 rforte