sanity-io / sanity-astro

https://www.sanity.io/plugins/sanity-astro
Other
73 stars 11 forks source link

[vite] Error when evaluating SSR module #92

Closed imdangle closed 8 months ago

imdangle commented 1 year ago

If you find a security vulnerability, do NOT open an issue. Email security@sanity.io instead.

Describe the bug

Error: [vite] Error when evaluating SSR module, __vite_ssr_import_2__.default is not a function. I followed the guide for integrating Astro and Sanity but when I ran 'yarn dev' and this error happened. If I comment sanity integration code block in astro.config.mjs, the error is gone.

To Reproduce

Steps to reproduce the behavior:

Follow these steps from The official Sanity integration for Astro

REPO

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Which versions of Sanity are you using?

Run sanity versions in the terminal and copy-paste the result here.

sanity 3.18.1

What operating system are you using? MacOS

Which versions of Node.js / npm are you running?

Run npm -v && node -v in the terminal and copy-paste the result here. 10.2.0 v18.18.0

Additional context

Add any other context about the problem here.

Security issue?

Any security issues should be submitted directly to [security@sanity.io](mailto:security@ Screenshot 2023-10-18 at 21 14 48 sanity.io). In order to determine whether you are dealing with a security issue, ask yourself these two questions:

flayks commented 1 year ago

Same issue here! Downgrading to 2.1.1 seems to fix it for now.

imdangle commented 1 year ago

Same issue here! Downgrading to 2.1.1 seems to fix it for now.

Confirmed! It's worked 😁. Thanks so much. But I think this issue should not closed.

RMunschie92 commented 1 year ago

Same issue here! Downgrading to 2.1.1 seems to fix it for now.

Confirming that this worked for me as well.

flayks commented 1 year ago

@kmelve @stipsan have you had a chance to look at it? 👀

Nivg commented 1 year ago

Same issue here! Downgrading to 2.1.1 seems to fix it for now.

Confirming that this worked for me as well, thanks!

dnsl48 commented 1 year ago

Looks like sanityIntegration is not the default export anymore (seems to be a bug).

A workaround for the latest version (2.1.4) seems to be solving the issue

salv0 commented 1 year ago

Any news about this?

still having the issue with:

"@sanity/astro": "^2.1.4",
"@sanity/client": "^6.8.0",
 "astro": "^3.5.2",
"sanity": "3.19.2",
elamandeep commented 1 year ago

Even after degrading it. Still having same issue

[vite] Error when evaluating SSR module /home/elamandeep/Desktop/Projects/newportfolio/src/pages/works.astro: failed to import "sanity:client"
|- Error: Cannot find module 'sanity:client' imported from '/home/elamandeep/Desktop/Projects/newportfolio/src/pages/works.astro'
    at nodeImport (file:///home/elamandeep/Desktop/Projects/newportfolio/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56088:25)
    at ssrImport (file:///home/elamandeep/Desktop/Projects/newportfolio/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:55990:30)
    at eval (/home/elamandeep/Desktop/Projects/newportfolio/src/pages/works.astro:5:37)
    at async instantiateModule (file:///home/elamandeep/Desktop/Projects/newportfolio/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56052:9)

 error   Cannot find module 'sanity:client' imported from '/home/elamandeep/Desktop/Projects/newportfolio/src/pages/works.astro'
Error: Cannot find module 'sanity:client' imported from '/home/elamandeep/Desktop/Projects/newportfolio/src/pages/works.astro'
    at nodeImport (file:///home/elamandeep/Desktop/Projects/newportfolio/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56088:25)
    at ssrImport (file:///home/elamandeep/Desktop/Projects/newportfolio/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:55990:30)
    at eval (/home/elamandeep/Desktop/Projects/newportfolio/src/pages/works.astro:5:37)
    at async instantiateModule (file:///home/elamandeep/Desktop/Projects/newportfolio/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:56052:9)
sandro-git commented 11 months ago

@salv0 try to add this in your asto.config.mjs

import { sanityIntegration } from  #"@sanity/astro";

remove

sanity()

from intergration and add this

sanityIntegration({
      projectId: "<project id>",
      dataset: "<name of database>",
      // Set useCdn to false if you're building statically.
      useCdn: false,
    }),
kmelve commented 8 months ago

Should be solved in #149 – thanks for reporting! (Astro requires a default export for npx astro add installation)