question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: require is not defined

See original GitHub issue

Describe the bug [vite] Error when evaluating SSR module /node_modules/gray-matter/index.js: ReferenceError: require is not defined

Logs

11:13:27 ├F10: AM┤ [vite] Error when evaluating SSR module /node_modules/gray-matter/index.js:
ReferenceError: require is not defined
    at /node_modules/gray-matter/index.js:3:12
    at instantiateModule (D:\learn\svelte\svelte-kit-demo\node_modules\vite\dist\node\chunks\dep-efe32886.js:68893:166)
11:13:51 ├F10: AM┤ [vite] Error when evaluating SSR module /node_modules/highlight.js/lib/index.js:
ReferenceError: require is not defined
    at /node_modules/highlight.js/lib/index.js:1:12    
    at instantiateModule (D:\learn\svelte\svelte-kit-demo\node_modules\vite\dist\node\chunks\dep-efe32886.js:68893:166)
11:13:51 ├F10: AM┤ [vite] Error when evaluating SSR module /node_modules/gray-matter/index.js:
ReferenceError: require is not defined
    at /node_modules/gray-matter/index.js:3:12
    at instantiateModule (D:\learn\svelte\svelte-kit-demo\node_modules\vite\dist\node\chunks\dep-efe32886.js:68893:166)
ReferenceError: require is not defined
    at /node_modules/highlight.js/lib/index.js:1:12    
    at instantiateModule (D:\learn\svelte\svelte-kit-demo\node_modules\vite\dist\node\chunks\dep-efe32886.js:68893:166)

To Reproduce Svelte: ^3.29.0 SvelteKit: ^1.0.0-next.55

repository:https://github.com/PingTouG/svelte-kit-demo

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Apr 3, 2021

I believe issues with the cookie library would be due to https://github.com/vitejs/vite/issues/2579

1reaction
benmccanncommented, Mar 29, 2021

It’s because Vite will try to optimize dependencies but not devDependencies: https://github.com/vitejs/vite/issues/826#issuecomment-694776869

It’s also possible that https://github.com/sveltejs/kit/pull/759 would have fixed this

I’m going to close this since it sounds like putting them in devDependencies is working

Read more comments on GitHub >

github_iconTop Results From Across the Web

Client on Node.js: Uncaught ReferenceError: require is not ...
However, require is not defined on the client side, and it throws an error of the form Uncaught ReferenceError: require is not defined...
Read more >
ReferenceError: require is not defined in JavaScript - Stack Diary
The "ReferenceError: require is not defined" error occurs when the require function is used in a JavaScript file that is intended to be ......
Read more >
How to fix "require is not defined" in JavaScript / Node.js?
In our case, the error message is “require is not defined” which indicates the problem is with the variable or method named “require”....
Read more >
How To Fix ReferenceError require is not defined in JavaScript
In this case, check your package.json file for an property called type . If that is set to module , ES6 modules will...
Read more >
Javascript - How to fix ReferenceError: require is not defined
This usually happens because your JavaScript environment doesn't understand how to handle the call to require() function you defined in your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found