【问题标题】:Create a UI package with Emotion and consume it with Next.js applicationCreate a UI package with Emotion and consume it with Next.js application
【发布时间】:2022-12-01 13:23:11
【问题描述】:

Problem:

We've built a UI package usingReact,Emotion, andVite. We're consuming it in a Next.js app.

But when we import a component, we get the following ServerError -

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

Seems like the cache object is null on the server. Even when adding <CacheProvider> to the Next.js app, we still get the same error.

Extra information:

Here's how our vite.config.js loos like -

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

import packageJson from './package.json';

export default defineConfig({
  plugins: [
    react({
      jsxImportSource: '@emotion/react',
      babel: {
        plugins: ['@emotion/babel-plugin'],
      },
    }),
  ],
  esbuild: {
    jsxInject: "import React from 'react'",
  },
  build: {
    outDir: 'lib',
    lib: {
      entry: './src/index',
      formats: ['esm'],
      fileName: (format) => `ui.${format}.js`,
    },
    rollupOptions: {
      // Externalize dependencies that shouldn't be bundled into library
      external: [...Object.keys(packageJson.peerDependencies)],
    },
  },
});

【问题讨论】:

    标签: reactjs package emotion


    【解决方案1】:

    did you find any solution? I have the same problem

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-18
      • 2022-08-17
      • 2012-04-28
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多