privateOmega / html-to-docx

HTML to DOCX converter
MIT License
373 stars 140 forks source link

Upgrading to React 18 throws .randomFillSync is not a function #204

Open hamodey opened 1 year ago

hamodey commented 1 year ago

Hi all,

I have been using this package for many years now on our production application and other applications. However, recently I have migrated from CRA to Vite for performance and help with the dev environment. Everything seemed to work perfectly okay, until using this library.

I am currently getting the following error:

image

I can see online this is due to a Node.js upgrade many years back - but I have been using Node 18 since release and things were working fine.

Could anyone please assist and point me in the right direction.

For reference:

/// <reference types="vite/client" />
/// <reference types="vitest" />
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from "path";
import EnvironmentPlugin from 'vite-plugin-environment'
import tsconfigPaths from 'vite-tsconfig-paths'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'

export default defineConfig(({ command }) => {

  return {
    //...rest
    plugins: [react(), EnvironmentPlugin('all', { prefix: 'VUE_APP_' }), tsconfigPaths()],
    optimizeDeps: {
      esbuildOptions: {
          define: {
              global: "globalThis",
          },
          plugins: [
            NodeModulesPolyfillPlugin(),
            NodeGlobalsPolyfillPlugin({
                  process: true,
                  buffer: true,
              }),
          ],
      },
  },
    resolve: {
      alias: {
      'components': path.resolve(__dirname, "./src/components"),
        'utils': path.resolve(__dirname, "./src/utils"),
        'pages': path.resolve(__dirname, "./src/pages"),
        'reducers': path.resolve(__dirname, "./src/reducers"),
        'types': path.resolve(__dirname, "./src/types"),
        'assets': path.resolve(__dirname, "./src/assets"),
        process: "process/browser",
        stream: "stream-browserify",
        zlib: "browserify-zlib",
        util: "util",
      }
    },
    ///...rest
  }
})