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

require is not defined when used with ESM via ViteJS #108

Open
stolinski opened this issue May 13, 2021 · 3 comments
Open

require is not defined when used with ESM via ViteJS #108

stolinski opened this issue May 13, 2021 · 3 comments
Labels

Comments

@stolinski
Copy link

Importing in an esm setup on the server seems to break.

Error when evaluating SSR module /node_modules/cross-fetch/dist/node-ponyfill.js:
ReferenceError: require is not defined
    at /node_modules/cross-fetch/dist/node-ponyfill.js:1:17

Not sure if this is related to #46

@benwoodward
Copy link

I'm also having this issue using https://github.com/dgraph-io/dgraph-js-http/ and SvelteKit + adapter-node

 node ./build
file:///Users/ben/dev/my-project/build/index.js:28
  throw new Error('Dynamic require of "' + x2 + '" is not supported');
        ^

Error: Dynamic require of "stream" is not supported
    at __require (file:///Users/ben/dev/my-project/build/index.js:28:9)
    at node_modules/node-fetch/lib/index.js (file:///Users/ben/dev/my-project/build/index.js:91:35)
    at __require2 (file:///Users/ben/dev/my-project/build/index.js:43:44)
    at node_modules/isomorphic-fetch/fetch-npm-node.js (file:///Users/ben/dev/my-project/build/index.js:1132:21)
    at __require2 (file:///Users/ben/dev/my-project/build/index.js:43:44)
    at node_modules/dgraph-js-http/lib/clientStub.js (file:///Users/ben/dev/my-project/build/index.js:4152:18)
    at __require2 (file:///Users/ben/dev/my-project/build/index.js:43:44)
    at node_modules/dgraph-js-http/lib/index.js (file:///Users/ben/dev/my-project/build/index.js:5142:19)
    at __require2 (file:///Users/ben/dev/my-project/build/index.js:43:44)
    at file:///Users/ben/dev/my-project/build/index.js:73298:25

esbuild:

var __require = (x2) => {
  if (typeof require !== "undefined")
    return require(x2);
  throw new Error('Dynamic require of "' + x2 + '" is not supported');
};

https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#01123

I think this is relevant: vitejs/vite#162

@eMeRiKa13
Copy link

Did you fix that @stolinski and @benwoodward? I have the same error with Nuxt3.

@benwoodward
Copy link

@eMeRiKa13 In my case this was a bug with SvelteKit's Node adapter iirc. I since switched to another adapter.

@lquixada lquixada added the esm label May 30, 2023
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

4 participants