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

Dev server error: ReferenceError: module is not defined (node_modules/cssesc/cssesc.js:73:1) #12229

Closed
1 task
lilnasy opened this issue Oct 14, 2024 · 3 comments · Fixed by #12232
Closed
1 task
Labels
- P2: has workaround Bug, but has workaround (priority) feat: view transitions Related to the View Transitions feature (scope)

Comments

@lilnasy
Copy link
Contributor

lilnasy commented Oct 14, 2024

Astro Info

Astro                    v4.16.3
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

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

No response

Describe the Bug

When vite.ssr.noExternal = true is set, no page can be accessed from the dev server. Production build is not impacted.

{97E1B4C7-895B-49DE-985E-9622DE12020A} {D430CCB9-5804-45A8-82D9-9A335BBDBABB}

What's the expected result?

vite.ssr has no effect on the dev server. Alternatively, cssesc-related issues only arise when its code is needed (i.e., in projects using view transitions), or cssesc can be detected as a commonjs module and be transpiled appropriately.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-jdp8df?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Oct 14, 2024
@martrapp
Copy link
Member

Hi Arsh! Good do hear from you again!

Let me take a look 👀

@martrapp martrapp added - P2: has workaround Bug, but has workaround (priority) and removed needs triage Issue needs to be triaged labels Oct 15, 2024
@martrapp
Copy link
Member

Surely you know the remedy, but for others who may stumble across it in the meantime, it's a quick fix:
In the astro.config re-add cssesc after noExternal: true

import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
  vite: {
-   ssr: { noExternal: true },
+   ssr: { noExternal: true, external: ['cssesc'] },
  },
});

@martrapp martrapp added the feat: view transitions Related to the View Transitions feature (scope) label Oct 15, 2024
@bluwy
Copy link
Member

bluwy commented Oct 15, 2024

We can add cssesc here

// These specifiers are usually dependencies written in CJS, but loaded through Vite's transform
// pipeline, which Vite doesn't support in development time. This hardcoded list temporarily
// fixes things until Vite can properly handle them, or when they support ESM.
const ONLY_DEV_EXTERNAL = [
// Imported by `@astrojs/prism` which exposes `<Prism/>` that is processed by Vite
'prismjs/components/index.js',
// Imported by `astro/assets` -> `packages/astro/src/core/logger/core.ts`
'string-width',
];

Though using ssr.noExternal: true in dev is kinda a rare case too since you're saying all your dependencies recursively export ESM, which isn't the case most of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: view transitions Related to the View Transitions feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants