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 createReactEditorJS #207

Open
faltawy opened this issue Aug 17, 2022 · 4 comments
Open

require is not defined createReactEditorJS #207

faltawy opened this issue Aug 17, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@faltawy
Copy link

faltawy commented Aug 17, 2022

  • @editorjs/editorjs version: x.y.z
  • react-editor-js version: x.y.z
  • vite

Bug discription

after building
Uncaught ReferenceError: require is not defined createReactEditorJS

@faltawy faltawy added the bug Something isn't working label Aug 17, 2022
@WildEgo
Copy link

WildEgo commented Aug 29, 2022

Hey mate, not the maintainer by any means of the imagination but you can fix this by using @originjs/vite-plugin-commonjs.

In your vite.config.(t/j)s you should have something like this:

import { defineConfig } from 'vite';
import { viteCommonjs, esbuildCommonjs } from '@originjs/vite-plugin-commonjs';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    viteCommonjs(),
  ],
  optimizeDeps:{
    esbuildOptions:{
      plugins:[
        esbuildCommonjs(['react-editor-js', '@react-editor-js/client', '@react-editor-js/server']) 
      ]
    }
  }
})

And your imports should work as something like this

// @ts-ignore: Workaround for CJS
import { createReactEditorJS } from 'react-editor-js/dist/react-editor-js.cjs';

I just got faced with the same problem and just fixed it rn.

Hope it helps,
Luis Bizarro.

@les19
Copy link

les19 commented Dec 13, 2022

Hey mate, not the maintainer by any means of the imagination but you can fix this by using @originjs/vite-plugin-commonjs.

In your vite.config.(t/j)s you should have something like this:

import { defineConfig } from 'vite';
import { viteCommonjs, esbuildCommonjs } from '@originjs/vite-plugin-commonjs';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    viteCommonjs(),
  ],
  optimizeDeps:{
    esbuildOptions:{
      plugins:[
        esbuildCommonjs(['react-editor-js', '@react-editor-js/client', '@react-editor-js/server']) 
      ]
    }
  }
})

And your imports should work as something like this

// @ts-ignore: Workaround for CJS
import { createReactEditorJS } from 'react-editor-js/dist/react-editor-js.cjs';

I just got faced with the same problem and just fixed it rn.

Hope it helps, Luis Bizarro.

@WildEgo THANK YOU SO MUCH!!! Works perfect!

@tam315
Copy link

tam315 commented Sep 29, 2023

ref: #236

@CyrusZei
Copy link

CyrusZei commented Jan 7, 2024

if that does not work, you can just add this to your vite config file

build: {
    commonjsOptions: { transformMixedEsModules: true }, // Change
  },

so something like this:

import { defineConfig } from "vite";
import path from "path";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  build: {
    commonjsOptions: { transformMixedEsModules: true }, // Change
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants