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

ReferenceError: require is not defined #655

Closed
PingTouG opened this issue Mar 25, 2021 · 11 comments
Closed

ReferenceError: require is not defined #655

PingTouG opened this issue Mar 25, 2021 · 11 comments
Labels

Comments

@PingTouG
Copy link

PingTouG commented Mar 25, 2021

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

@Rich-Harris Rich-Harris added the bug Something isn't working label Mar 25, 2021
@devrnt
Copy link
Contributor

devrnt commented Mar 25, 2021

Could be related to vitejs/vite#2579 & vitejs/vite#2667

@benmccann benmccann added support vite and removed bug Something isn't working labels Mar 29, 2021
@benmccann
Copy link
Member

benmccann commented Mar 29, 2021

I do not think those issues are related

Can you try adding this to devDependencies? And also try adding it to exclude inside optimizeDeps?

@devrnt
Copy link
Contributor

devrnt commented Mar 29, 2021

Both suggestions don't to work. What does work is dropping gray-matter from ssr.noExternal

@devrnt
Copy link
Contributor

devrnt commented Mar 29, 2021

The SvelteKit starter comes with this line noExternal: Object.keys(pkg.dependencies || {}), so I think it's there with a reason?

Update: reason

@benmccann benmccann added bug Something isn't working and removed support labels Mar 29, 2021
@devrnt
Copy link
Contributor

devrnt commented Mar 29, 2021

@benmccann

Both suggestions don't to work. What does work is dropping gray-matter from ssr.noExternal

Moving these deps do devDepedencies does actually work, still trying to figure why Does this also need to be done for other client dependencies? Yes, it does. is true

@benmccann benmccann added support and removed bug Something isn't working labels Mar 29, 2021
@benmccann
Copy link
Member

It's because Vite will try to optimize dependencies but not devDependencies: vitejs/vite#826 (comment)

It's also possible that #759 would have fixed this

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

@benmccann benmccann mentioned this issue Mar 29, 2021
Closed
@devrnt
Copy link
Contributor

devrnt commented Mar 29, 2021

FYI Still having the same issue after #759. It's good the have the follow-up in #581, thanks. Also SvelteKit is awesome

@Rastavich
Copy link

I'm not sure if this is right place to comment and please correct me if I have done this wrong but I am having a very similar issue.

If I don't include "cookie" in my noExternal in svelte.config.cjs and I try and run a npm run build to Vercel, I get errors on build as below;

image

It makes no difference if cookie is in package.json as either a dependencies or devDependencies.

If I have "cookie" in my noExternal then I can run a successful Vercel build but when pnpm run dev on my local I get errors from vite as below;

image

@benmccann
Copy link
Member

I believe issues with the cookie library would be due to vitejs/vite#2579

@BetaConnector
Copy link

BetaConnector commented Apr 4, 2021

@benmccann, same problem with faunadb - the database of netlify.
It's needed within the dependencies - moving this to devDependencies is not an option, since it's needed within a function.

This issue should not be considered as closed.
image

Even the build command fails with

        vite: {
            ssr: {
                noExternal: Object.keys(pkg.dependencies || {}),
            },
        }

image

I tracked down the issue:
/node_modules/faunadb/src/values.js
image

Sice faunadb is the db for netlify, this is a show stopper at this point :(

@benmccann
Copy link
Member

Issues with loading various modules should generally be filed over at https://github.com/vitejs/vite since that's where the issue is coming from and there's not much we can do within SvelteKit to address it

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

No branches or pull requests

6 participants