Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vercel is not working in a monorepo #4567

Closed
1 task
snorreks opened this issue Aug 31, 2022 · 11 comments
Closed
1 task

Vercel is not working in a monorepo #4567

snorreks opened this issue Aug 31, 2022 · 11 comments

Comments

@snorreks
Copy link

snorreks commented Aug 31, 2022

What version of astro are you using?

1.1.1

Are you using an SSR adapter? If so, which one?

@astrojs/vercel

What package manager are you using?

npm

What operating system are you using?

Windows

Describe the Bug

When vercel has deployed I get

2022-08-31T09:39:48.226Z	undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@astrojs/vercel' imported from /var/task/entry.js
    at new NodeError (node:internal/errors:372:5)
    at packageResolve (node:internal/modules/esm/resolve:954:9)
    at moduleResolve (node:internal/modules/esm/resolve:1003:20)
    at defaultResolve (node:internal/modules/esm/resolve:1218:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
RequestId: 1dc723e6-1657-4c14-88ab-7c0a879065ae Error: Runtime exited with error: exit status 1
Runtime.ExitError
Vercel Build log
[14:22:14.130] Cloning github.com/snorreks/astro-monorepo-vercel (Branch: master, Commit: 72c4e23)
[14:22:14.322] Cloning completed: 191.394ms
[14:22:15.250] Looking up build cache...
[14:22:15.549] Build Cache not found
[14:22:15.576] Running "vercel build"
[14:22:16.116] Vercel CLI 28.2.2
[14:22:16.350] Running "install" command: `cd ../.. && npm i`...
[14:22:23.683] npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
[14:22:26.087] 
[14:22:26.087] added 525 packages, and audited 526 packages in 10s
[14:22:26.087] 
[14:22:26.087] 182 packages are looking for funding
[14:22:26.087]   run `npm fund` for details
[14:22:26.112] 
[14:22:26.112] found 0 vulnerabilities
[14:22:26.406] 
[14:22:26.406] > build
[14:22:26.406] > npm --prefix apps/astro-app run build
[14:22:26.407] 
[14:22:26.706] 
[14:22:26.706] > build
[14:22:26.706] > astro build
[14:22:26.706] 
[14:22:28.215] 12:22:28 PM [build] output target: server
[14:22:28.216] 12:22:28 PM [build] deploy adapter: @astrojs/vercel/serverless
[14:22:28.216] 12:22:28 PM [build] Collecting build info...
[14:22:28.216] 12:22:28 PM [build] Completed in 10ms.
[14:22:28.217] 12:22:28 PM [build] Building server entrypoints...
[14:22:30.375] 12:22:30 PM [build] Completed in 2.16s.
[14:22:30.383] 
[14:22:30.383]  finalizing server assets 
[14:22:30.383] 
[14:22:30.383] 12:22:30 PM [build] Rearranging server assets...
[14:22:30.495] 12:22:30 PM [build] Server built in 2.29s
[14:22:30.495] 12:22:30 PM [build] Complete!
[14:22:30.524] Build Completed in /vercel/output [14s]
[14:22:33.792] Generated build outputs:
[14:22:33.793]  - Static files: 0
[14:22:33.794]  - Serverless Functions: 1
[14:22:33.794]  - Edge Functions: 0
[14:22:33.794] Serverless regions: Washington, D.C., USA
[14:22:33.794] Deployed outputs in 3s
[14:22:35.545] Build completed. Populating build cache...
[14:22:41.986] Uploading build cache [31.28 MB]...
[14:22:43.588] Build cache uploaded: 1.602s
[14:22:43.616] Done with "."

when i access the site https://astro-monorepo-vercel.vercel.app/.

It works locally, and vercel can deploy.

I am having the project in a sub directory. But this setup works with a svelte-kit project using the same Vercel config and vite config (@sveltejs/adapter-vercel).

I see the code in .vercel\output\functions\render.func\entry.js imports:

import * as adapter from '@astrojs/vercel/serverless/entrypoint';
import 'path-browserify';

Link to Minimal Reproducible Example

https://github.com/snorreks/astro-monorepo-vercel

Participation

  • I am willing to submit a pull request for this issue.
@snorreks snorreks changed the title Astro not working with nx and @astrojs/vercel Serverless Function not working on vercel with nx Aug 31, 2022
@matthewp
Copy link
Contributor

matthewp commented Sep 1, 2022

How is nx related to this problem?

@snorreks snorreks changed the title Serverless Function not working on vercel with nx Vercel is not working in a monorepo Sep 3, 2022
@snorreks
Copy link
Author

snorreks commented Sep 3, 2022

Sorry, this is not specifically nx problem but monorepo in general. I have updated the description and created a new github example without nx and I still get the same error.

@kkarimi
Copy link

kkarimi commented Sep 3, 2022

I can reproduce - I am using in a mono repo with NX - Astro 1.1.5 and I have the same issue - though I don't think it has anything to do with NX either:

2022-09-03T23:30:05.643Z	undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@astrojs/vercel' imported from /var/task/entry.js
    at new NodeError (node:internal/errors:372:5)
    at packageResolve (node:internal/modules/esm/resolve:954:9)
    at moduleResolve (node:internal/modules/esm/resolve:1003:20)
    at defaultResolve (node:internal/modules/esm/resolve:1218:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
RequestId: 42b5db20-ec1d-4485-83d8-b9fe863a4446 Error: Runtime exited with error: exit status 1
Runtime.ExitError

I tried moving it in to dependencies from devDependencies but it did not have any effect

@newtonharry
Copy link

I'm experiencing the same issue when I try to deploy from a github repo. When I deploy using the vercel CLI the function no longer produces the error message and the application starts working.

I'm using the PNPM package manager.

This is my package.json:

{
  "name": "@example/basics",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro build",
    "preview": "astro preview",
    "astro": "astro"
  },
  "devDependencies": {
    "@astrojs/react": "^1.0.0",
    "@astrojs/tailwind": "^1.0.0",
    "@types/node": "^18.7.15",
    "astro": "^1.0.8",
    "react": "^18.0.0",
    "react-dom": "^18.0.0"
  },
  "dependencies": {
    "@astrojs/vercel": "^1.0.2",
    "astro-icon": "^0.7.3",
    "autoprefixer": "^10.4.8",
    "daisyui": "^2.24.0",
    "date-fns": "^2.29.2",
    "dotenv": "^16.0.2",
    "postcss": "^8.4.16",
    "svgo": "^2.8.0",
    "typewriter-effect": "^2.19.0"
  }
}

Here is my build logs:

[17:04:20.816] Downloading 21 deployment files...
[17:04:22.389] Looking up build cache...
[17:04:22.644] Build Cache not found
[17:04:22.684] Running "vercel build"
[17:04:23.330] Vercel CLI 28.2.2
[17:04:23.703] Detected `pnpm-lock.yaml` generated by pnpm 7...
[17:04:23.719] Installing dependencies...
[17:04:24.454] Lockfile is up to date, resolution step is skipped
[17:04:24.498] Progress: resolved 1, reused 0, downloaded 0, added 0
[17:04:24.682] Packages: +581
[17:04:24.683] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[17:04:25.253] Packages are hard linked from the content-addressable store to the virtual store.
[17:04:25.253]   Content-addressable store is at: /vercel/.local/share/pnpm/store/v3
[17:04:25.253]   Virtual store is at:             node_modules/.pnpm
[17:04:25.499] Progress: resolved 581, reused 0, downloaded 32, added 20
[17:04:26.510] Progress: resolved 581, reused 0, downloaded 122, added 116
[17:04:27.522] Progress: resolved 581, reused 0, downloaded 194, added 190
[17:04:28.525] Progress: resolved 581, reused 0, downloaded 252, added 249
[17:04:29.525] Progress: resolved 581, reused 0, downloaded 317, added 315
[17:04:30.534] Progress: resolved 581, reused 0, downloaded 412, added 403
[17:04:31.541] Progress: resolved 581, reused 0, downloaded 511, added 501
[17:04:32.552] Progress: resolved 581, reused 0, downloaded 573, added 573
[17:04:33.552] Progress: resolved 581, reused 0, downloaded 578, added 578
[17:04:34.556] Progress: resolved 581, reused 0, downloaded 581, added 581, done
[17:04:34.850] .../[email protected]/node_modules/esbuild postinstall$ node install.js
[17:04:34.944] .../[email protected]/node_modules/esbuild postinstall: Done
[17:04:35.123] 
[17:04:35.124] dependencies:
[17:04:35.124] + @astrojs/vercel 1.0.2
[17:04:35.128] + astro-icon 0.7.3
[17:04:35.128] + autoprefixer 10.4.8
[17:04:35.128] + daisyui 2.24.2
[17:04:35.129] + date-fns 2.29.2
[17:04:35.129] + dotenv 16.0.2
[17:04:35.129] + postcss 8.4.16
[17:04:35.130] + svgo 2.8.0
[17:04:35.130] + typewriter-effect 2.19.0
[17:04:35.130] 
[17:04:35.131] devDependencies:
[17:04:35.131] + @astrojs/react 1.1.1
[17:04:35.131] + @astrojs/tailwind 1.0.0
[17:04:35.131] + @types/node 18.7.15
[17:04:35.132] + astro 1.1.5
[17:04:35.132] + react 18.2.0
[17:04:35.132] + react-dom 18.2.0
[17:04:35.132] 
[17:04:35.191] Running "pnpm run build"
[17:04:35.841] 
[17:04:35.842] > @example/[email protected] build /vercel/path0
[17:04:35.842] > astro build
[17:04:35.842] 
[17:04:38.431] 07:04:38 AM [build] output target: server
[17:04:38.432] 07:04:38 AM [build] deploy adapter: @astrojs/vercel/serverless
[17:04:38.432] 07:04:38 AM [build] Collecting build info...
[17:04:38.433] 07:04:38 AM [build] Completed in 56ms.
[17:04:38.434] 07:04:38 AM [build] Building server entrypoints...
[17:04:40.680] 
[17:04:40.680] �[35m🌼 daisyUI components 2.24.2�[0m �[0m https://github.com/saadeghi/daisyui
[17:04:41.109]   �[32m✔︎ Including:�[0m �[0m base, components, themes[29], utilities
[17:04:41.109]   
[17:04:42.932] 07:04:42 AM [build] Completed in 4.50s.
[17:04:42.932] 
[17:04:42.932]  building client 
[17:04:44.175] Completed in 1.24s.
[17:04:44.175] 
[17:04:44.181] 
[17:04:44.181]  finalizing server assets 
[17:04:44.181] 
[17:04:44.181] 07:04:44 AM [build] Rearranging server assets...
[17:04:47.195] 07:04:47 AM [build] Waiting for the @astrojs/vercel/serverless integration...
[17:04:47.737] 07:04:47 AM [build] Server built in 9.36s
[17:04:47.738] 07:04:47 AM [build] Complete!
[17:04:48.442] Build Completed in /vercel/output [25s]
[17:04:53.146] Generated build outputs:
[17:04:53.146]  - Static files: 6
[17:04:53.146]  - Serverless Functions: 1
[17:04:53.146]  - Edge Functions: 0
[17:04:53.146] Serverless regions: Washington, D.C., USA
[17:04:53.147] Deployed outputs in 3s
[17:04:53.880] Build completed. Populating build cache...
[17:05:12.372] Uploading build cache [34.67 MB]...
[17:05:13.421] Build cache uploaded: 1.050s
[17:05:13.457] Done with "."```

@pablodavila95
Copy link

I'm getting the same error when deploying to Vercel. Anyone got any updates on this?

@sammccord
Copy link

So this is a temporary workaround, but I was able to get it working by changing my install command to npm install, and not having any npm workspace config in .npmrc or the root package.json.

I believe that this due to some symlink weirdness when vercel copies deps to a node_modules local to the entry.js in .vercel/output/functions/render.func. Not sure how to go about fixing, though.

@matthewp
Copy link
Contributor

matthewp commented Oct 6, 2022

We recently fixed hoisting, so this should be working in 1.4.0+! If you are still seeing the problem please file a new issue.

@nestorbfgo
Copy link

@matthewp I'm facing the same error when I use astro and vercel adapter on a monorepo, i see that this conversation is closed but for me it's not clear how this was fixed, so please would be great a detailed explanation about it

@prodkt
Copy link

prodkt commented Oct 2, 2023

This issue persists with all the latest releases. Should not be closed.

@ematipico
Copy link
Member

@nestorbfgo @prodkt the original poster hasn't replied, so we assume the issue is fixed.

If you are still affected, please follow Matthew's advice and create a new issue. You never know that your issue is caused by something else. And, maybe, add a comment here with the link to the new issue as a follow up for other developers.

@btakita
Copy link

btakita commented Nov 30, 2023

@nestorbfgo @prodkt Have either of you created a separate issue? I'm having the same problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants