Задать вопрос
alaskafx
@alaskafx
Не .do Frontend

Cannot read properties of undefined (reading 'button')?

Делаю свою ui библиотеку для локального использования между проектами.
Решил лить свой проект через gitlab, все сделал, однако, при попытке использовать вылазит подобная ошибка:
Cannot read properties of undefined (reading 'button')


Использую: webpack, ts, react, css modules, class-variance-authority.

Ошибка кидает именно на строку, где cva пытается достать класс .button.
Код выглядит так:

Button.tsx:
import styles from "./Button.module.css";
import { cva, type VariantProps } from "class-variance-authority";
import React, { type ButtonHTMLAttributes } from "react";

const button = cva(styles.button, {
	variants: {
		intent: {
			default: styles.buttonDefault,
			accent: styles.buttonAccent,
			stroke: styles.buttonStroke,
			disabled: styles.buttonDisabled,
			withoutBg: styles.buttonWithoutBg,
		},

	},
	defaultVariants: {
		intent: "default",
	},
});
 
export interface ButtonProps
		extends ButtonHTMLAttributes<HTMLButtonElement>,
				VariantProps<typeof button> {}

export const Button = ({ className, intent, ...props }: ButtonProps) => {
	return <button className={button({ intent, className })} {...props} />;
};


webpack.config.js:

const path = require("path");

module.exports = {
  mode: "production",
  entry: "./src/index.ts",
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "dist"),
    clean: true,
    libraryTarget: "umd",
  },
  resolve: {
    extensions: [".ts", ".tsx"],
  },
  externals: {
    react: "react",
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)?$/,
        use: ["ts-loader"],
        exclude: /node_modules/,
      },
      {
        test: /\.css$/i,
        use: [
          {
            loader: "style-loader",
          },
          { loader: "css-modules-typescript-loader" },
          { 
            loader: "css-loader", 
            options: { modules: true } 
        },
        ],
      },
    ],
  },
};
  • Вопрос задан
  • 210 просмотров
Подписаться 1 Простой 4 комментария
Помогут разобраться в теме Все курсы
  • Яндекс Практикум
    Профессиональная вёрстка на HTML и CSS
    3 месяца
    Далее
  • Skillbox
    Веб-вёрстка 3.0
    3 месяца
    Далее
  • OTUS
    HTML/CSS
    3 месяца
    Далее
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
ITK academy Нижний Новгород
от 50 000 до 90 000 ₽
FoodSoul Калининград
от 180 000 до 250 000 ₽
Data Directs Тель-Авив
от 350 000 ₽