Git Product home page Git Product logo

Comments (5)

johnrdoty92 avatar johnrdoty92 commented on June 21, 2024 1

@michalbujalski Are you getting that error after running yarn preview? Can you show what your config looks like for the optimizeDeps option? You could also try changing your definition of global to globalThis:

define: {
  global: "globalThis",
},

Also, if you see any errors in the dev tools console about require, you might need to add the following to your build option:

commonjsOptions: {
  transformMixedEsModules: true,
},

from hashconnect.

johnrdoty92 avatar johnrdoty92 commented on June 21, 2024

@michalbujalski Have you tried adding the rollup-plugin-node-polyfills plugin to the rollupOptions?

import nodePolyfills from "rollup-plugin-node-polyfills";

export default defineConfig({
  // add the following to the rest of your config:
  build: {
    rollupOptions: {
      plugins: [ nodePolyfills() as any],
    }
  }
})

from hashconnect.

michalbujalski avatar michalbujalski commented on June 21, 2024

Yes, I got the same result

from hashconnect.

bdxndev avatar bdxndev commented on June 21, 2024

any update on a fix

from hashconnect.

damiano-melcarne-lab49 avatar damiano-melcarne-lab49 commented on June 21, 2024

I ran into a similar set of issues with a Vite+React application. A local build worked as expected but the same build deployed to Netlify would throw the following errors in the Chrome DevTools console:

Uncaught ReferenceError: global is not defined
Uncaught ReferenceError: require is not defined
Uncaught ReferenceError: Buffer is not defined

Setting the transformMixedEsModules field to true and adding global node polyfills fixed these issues:

/* vite.config.ts */
import { nodePolyfills } from "vite-plugin-node-polyfills";
/* ... other  config ... */

export default defineConfig({
/* ... other  config ... */
build: {
    commonjsOptions: {
      transformMixedEsModules: true,
    },
  },
plugins: [
    nodePolyfills({
      globals: {
        Buffer: true,
        global: true,
        process: true,
      },
    }),
  ]
})

transformMixedEsModules: true enables mixed module transformations. This is useful for scenarios where modules include a mix of ES import statements and CommonJS require statements. Setting transformMixedEsModules to true transforms require statements to import statements (and vice versa for false). This is useful for bundling hashconnect since the ES esm/hashconnect.js file uses a CommonJS 'require' statement to import buffer: global.Buffer = global.Buffer || require('buffer').Buffer;.

The node polyfills should fix the errors related to the 'not defined' global variables.

from hashconnect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.