为什么Rollup不编译我的样式组件

发布于 2025-02-12 15:59:23 字数 2334 浏览 1 评论 0原文

我很高兴我的组件lib与常规CSS一起使用,但是现在我试图添加样式的组件,突然间,我得到了错误(在正在导入LIB的项目上)

TypeError: Cannot read property 'useDebugValue' of null
styled.button

我真的尝试了所有内容,我在网上搜索了所有内容因此,但是什么都找不到。这只是令人沮丧的,希望你们能帮助我。

rolup.config.js

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from 'rollup-plugin-babel'
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
import postcss from 'rollup-plugin-postcss';

const packageJson = require('./package.json');
export default [
    {
        input: 'src/index.ts',
        output: [
            {
                file: packageJson.main,
                format: 'cjs',
                sourcemap: true,
            },
            {
                file: packageJson.module,
                format: 'esm',
                sourcemap: true,
            },
        ],
        plugins: [resolve(), commonjs(), babel({plugins: ['babel-plugin-styled-components'], exclude: 'node_modules/**'}), typescript({ tsconfig: './tsconfig.json' }), postcss()],
    },

    {
        input: 'dist/esm/types/index.d.ts',
        output: [{ file: 'dist/index.d.ts', format: 'esm', sourcemap: true,
    globals: { 'styled-components': 'styled' } }],
        plugins: [dts()],
    external: ['react', 'styled-components'],
    },
];

babel.config.js

module.exports = {
    presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
  plugins: ['babel-plugin-styled-components',  {
    namespace: 'appname-',
    displayName: false,
    fileName: false
  }]
};

src/components/button/button/styles.ts

import styled from "styled-components";

export const ButtonPrimary = styled.button`
  background-color: #0070f3;
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 24px;
  text-transform: uppercase;
  transition: background-color 0.2s ease-in-out;
  &:hover {
    background-color: #0060e6;
  }
  &:active {
    background-color: #0050d6;
  }
  &:focus {
    outline: none;
  }
  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
`;

我希望您能为我提供帮助,如果您需要更多信息请告诉我。

此致 knome

I was so happy that my Component Lib works with regular CSS but now I am trying to add styled components and of a sudden, I get the error (on the project which is importing the lib)

TypeError: Cannot read property 'useDebugValue' of null
styled.button

I really tried everything, I searched on the web and SO but couldn't find anything. It is just frustrating and hopefully you guys can help me.

rollup.config.js

import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from 'rollup-plugin-babel'
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
import postcss from 'rollup-plugin-postcss';

const packageJson = require('./package.json');
export default [
    {
        input: 'src/index.ts',
        output: [
            {
                file: packageJson.main,
                format: 'cjs',
                sourcemap: true,
            },
            {
                file: packageJson.module,
                format: 'esm',
                sourcemap: true,
            },
        ],
        plugins: [resolve(), commonjs(), babel({plugins: ['babel-plugin-styled-components'], exclude: 'node_modules/**'}), typescript({ tsconfig: './tsconfig.json' }), postcss()],
    },

    {
        input: 'dist/esm/types/index.d.ts',
        output: [{ file: 'dist/index.d.ts', format: 'esm', sourcemap: true,
    globals: { 'styled-components': 'styled' } }],
        plugins: [dts()],
    external: ['react', 'styled-components'],
    },
];

babel.config.js

module.exports = {
    presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
  plugins: ['babel-plugin-styled-components',  {
    namespace: 'appname-',
    displayName: false,
    fileName: false
  }]
};

src/components/Button/styles.ts

import styled from "styled-components";

export const ButtonPrimary = styled.button`
  background-color: #0070f3;
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 24px;
  text-transform: uppercase;
  transition: background-color 0.2s ease-in-out;
  &:hover {
    background-color: #0060e6;
  }
  &:active {
    background-color: #0050d6;
  }
  &:focus {
    outline: none;
  }
  box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
`;

I hope you can help me and if you need more Info please tell me.

Best Regards
Knome

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文