Skip to content

Cannot find package 'cookie' - Vercel Adapter - hybrid and server outputs #9801

@fabiobiondi

Description

@fabiobiondi

Astro Info

Astro                    v4.2.3
Node                     v18.17.1 (also tried with Node v20)
System                   macOS (arm64)
Package Manager          unknown
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/react
                         @astrojs/tailwind
                         @astrojs/mdx
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have migrated a website from Astro v.1 (SSG) to v.4 (hybrid).
There are hundred of images, dozens of markdown and more or less 200 Astro components.

Since I had some problems with the migration I decided to create a brand new project with v.4.2.3.

The astro.config.mjs is pretty simple:

import { defineConfig } from 'astro/config';
import vercelServerless from '@astrojs/vercel/serverless';
import react from "@astrojs/react";
import mdx from "@astrojs/mdx";

// https://astro.build/config
export default defineConfig({
  site: 'https://www.fabiobiondi.dev/',
  output: 'hybrid',
  adapter: vercelServerless(),

  integrations: [react(), mdx()],
});

Using Static Rendering:
the build works fine in both, locally and deployed on Vercel ✅

Using hybrid output:
• dev: works ✅
• production (Vercel) ❌: static pages work fine while when I open pages with export const prerender = false I got this error:

<<
This Serverless Function has crashed.
...

This page just contains the following code:

---
export const prerender = false;
---
hello

Using server output:
• dev: works ✅
• production (Vercel) ❌: all non-static pages have problems


This is the error I read from Vercel Logs, when I visit the SSR page:

undefined	ERROR	Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'cookie' imported from /var/task/.vercel/output/_functions/entry.mjs
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:895:9)
    at moduleResolve (node:internal/modules/esm/resolve:988:20)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:939:12)
    at defaultResolve (node:internal/modules/esm/resolve:1181:79)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_MODULE_NOT_FOUND'

In the .vercel folder I see that the entry.mjs file cannot find the cookie library (but it's available in node_modules folder:

image

NOTE: I have also tried to install cookie on my project as dependency and peer Dependency

Have you some ideas or advice?
Thank you 🙏

What's the expected result?

SSR pages should work on Vercel

Link to Minimal Reproducible Example

n/a

Metadata

Metadata

Assignees

Labels

- P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: vercelRelated to Vercel adapter (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions