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

Cannot read properties of null (reading 'registered') - Next.js #8461

Open
3 tasks
zgrybus opened this issue Apr 24, 2024 · 0 comments
Open
3 tasks

Cannot read properties of null (reading 'registered') - Next.js #8461

zgrybus opened this issue Apr 24, 2024 · 0 comments

Comments

@zgrybus
Copy link

zgrybus commented Apr 24, 2024

Description

Hi!

I use @chakra-ui/react (v2.8.2) inside my Next.js App this way ( and this is working fine! ):

import { Flex } from '@chakra-ui/react';

const MyNewComponent = () => (
 <Flex>Wonderful component</Flex>
)

But when I try to create totally new component's library that uses @chakra-ui/react ( basically my component's library will export this MyNewComponent component ) and use it inside Next.js application I'm getting this error

// components_library/main.ts of the component's library
export { Flex } from '@chakra-ui/react';

// next_js_app/src/components/Component.ts file where I use components library
import { Flex } from 'components-library';

const MyNewComponent = () => (
 <Flex>Wonderful component</Flex>
)

Server Error
TypeError: Cannot read properties of null (reading 'registered')

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Other components that used external libraries are working fine. The problem is only with @chakra-ui/react library.

Any ideas?

Basically, the error happens only when I bundle the @chakra-ui/react 🤔
This is vite.config.ts of my components library

import path from 'node:path';

import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
  plugins: [
    tsconfigPaths(),
    dts({
      exclude: ['packages/lib/**/*.stories.tsx'],
      insertTypesEntry: true,
    }),
  ],
  build: {
    lib: {
      entry: path.resolve(__dirname, './packages/lib/main.tsx'),
      name: 'components-library',
      formats: ['es'],
    },
    emptyOutDir: true,
    rollupOptions: {
      external: [
        'react',
        'react-dom'
      ],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },
});

This issue is similar I guess
JedWatson/react-select#5555

Link to Reproduction

not provided

Steps to reproduce

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Chakra UI Version

2.8.2

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant