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

Error: Cannot read properties of undefined (reading 'createContext') #431

Open
cassio-gamarra opened this issue Nov 21, 2023 · 6 comments
Open
Labels
pending:feedback This issue is blocked by necessary feedback.

Comments

@cassio-gamarra
Copy link

image

This errors occurs after build the project. In development time don't happs.

I'm using Vite to build.

My vite.config.ts file:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import tsconfigPaths from 'vite-tsconfig-paths';
export default defineConfig({
  plugins: [react(), tsconfigPaths()],
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id
              .toString()
              .split('node_modules/')[1]
              .split('/')[0]
              .toString();
          }
        },
      },
    },
  },
});
@Witoso
Copy link
Member

Witoso commented Nov 22, 2023

You need to use our Vite plugin as well.

@Witoso Witoso added the pending:feedback This issue is blocked by necessary feedback. label Nov 22, 2023
@cassio-gamarra
Copy link
Author

I add vite plugin e build again:
image

Same error:
image

Using the editor:
image
image

My package.json references "react": "^18.2.0" and the build machine is using node v20.9.0.

@Witoso
Copy link
Member

Witoso commented Nov 27, 2023

As far as I can see, you're using a predefined build, it doesn't require any Vite plugin, as the code is already built in the npm package.

@cassio-gamarra
Copy link
Author

Any idea how i fix the reading 'createContext' error?

@Witoso
Copy link
Member

Witoso commented Nov 28, 2023

I would appreciate it if you could prepare some reproducible code sample for us (repo or zip).

@MohamedKarrab
Copy link

MohamedKarrab commented Apr 29, 2024

Same error here, after building using npm run build
vite.config.mjs

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import commonjs from "vite-plugin-commonjs";
export default defineConfig(() => {
    return {
        plugins: [
            react(),
            commonjs({
                filter(id) {
                    if (["libs/ckeditor5/build/ckeditor.js"].includes(id)) {
                        return true;
                    }
                },
            }),
        ],
        optimizeDeps: {
            include: ["ckeditor5-custom-build"],
        },
        build: {
            commonjsOptions: { exclude: ["ckeditor5-custom-build"] },
            outDir: 'build',
            rollupOptions: {
                output:{
                    manualChunks(id) {
                        if (id.includes('node_modules')) {
                            return id.toString().split('node_modules/')[1].split('/')[0].toString();
                        }
                    }
                }
            }
        },
    };
});

Though it works fine without the rollupOptions, but I need them.
Edit:
I fixed this after adding `if (id.includes('commonjsHelpers')) return 'commonjsHelpers' to the manual chunking:

manualChunks(id) {
                        if (id.includes('commonjsHelpers')) return 'commonjsHelpers'
                        if (id.includes('node_modules')) {
                            return id.toString().split('node_modules/')[1].split('/')[0].toString();
                        }
                    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending:feedback This issue is blocked by necessary feedback.
Projects
None yet
Development

No branches or pull requests

3 participants