тематический пакет пользовательского интерфейса для экспорта материалов

Я хочу создать новый пакет npm, в который я могу экспортировать все компоненты @material-ui/core, но по-своему. В настоящее время используется машинописный текст и накопительный пакет, но он терпит неудачу. это мой код

index.ts

export { Button } from '@material-ui/core'; 

пакет.json

{
  "name": "@ripley-ui/core",
  "version": "1.0.0",
  "description": "",
  "main": "build/index.js",
  "module": "build/index.esm.js",
  "types": "build/index.d.ts",
  "files": [
    "build"
  ],
  "scripts": {
    "build": "rollup -c",
    "storybook": "start-storybook -p 6006",
    "storybook:export": "build-storybook",
    "test": "jest",
    "test:watch": "jest --watch"
  },
  "author": "",
  "license": "ISC",
  "peerDependencies": {
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "devDependencies": {
    "@babel/core": "^7.10.4",
    "@rollup/plugin-commonjs": "^13.0.0",
    "@rollup/plugin-node-resolve": "^8.1.0",
    "@storybook/react": "^5.3.19",
    "@testing-library/jest-dom": "^5.11.0",
    "@testing-library/react": "^10.4.5",
    "@types/jest": "^26.0.4",
    "@types/react": "^16.9.43",
    "babel-loader": "^8.1.0",
    "babel-preset-react-app": "^9.1.2",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^26.1.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "rollup": "^2.21.0",
    "rollup-plugin-peer-deps-external": "^2.2.3",
    "rollup-plugin-typescript2": "^0.27.1",
    "ts-jest": "^26.1.1",
    "typescript": "^3.9.6"
  },
  "dependencies": {
    "@material-ui/core": "^4.11.0"
  }
}

rollup.config.js

import external from "rollup-plugin-peer-deps-external";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";

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
    }
  ],
  external: ["react", "@material-ui/core"],
  plugins: [
    external(),
    resolve(),
    typescript({
      rollupCommonJSResolveHack: true,
      clean: true
    }),
    commonjs(),
  ]
};

и tsconfing.json

{
  "compilerOptions": {
    "rootDir": "src",
    "declaration": true,
    "declarationDir": "build",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom", "es2016", "es2017"],
    "sourceMap": true,
    "jsx": "react",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"],
  "exclude": [
    "node_modules",
    "build",
    "storybook-static",
    "src/**/*.stories.tsx",
    "src/**/*.test.tsx"
  ]
}

и ошибка, которую он получает при импорте кнопки в новое приложение,

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

Помогите, пожалуйста!

ОБНОВЛЕНИЕ

Я сделал еще один тест, на этот раз создав и экспортировав новый компонент, сделанный мной, и все еще получаю ту же ошибку недопустимого вызова ловушки, вот код!

import React, { useState } from "react";

import { TestComponentProps } from "./TestComponent.types";


const TestComponent: React.FC<TestComponentProps> = ({ theme }) => {
  const [state, setState] = useState('prueba')
  return (
  <div
    data-testid="test-component"
    className={`test-component test-component-${theme}`}
  >
    <h2>{state}</h2>
  </div>
)};

export default TestComponent;

так что, может быть, проблема с моим упаковщиком или компилятором?


person Francisco Castillo    schedule 23.07.2020    source источник
comment
Вы должны еще раз проверить, какие ваши компоненты используют такие хуки, как makeStyles()?   -  person Michael    schedule 23.07.2020
comment
@Michael Майкл да, все компоненты материального пользовательского интерфейса имеют этот хук makeStyles (), но не знаю, как это сделать неправильно   -  person Francisco Castillo    schedule 23.07.2020
comment
Можете ли вы показать мне код, который использует makeStyles()?   -  person Michael    schedule 23.07.2020
comment
@Michael вот документация makeStyles() material-ui.com /styles/api/#makestyles-styles-options-hook НО, я сделал еще один тест, я обновил выше, чтобы вы могли видеть, как мой тупой компонент пытается использовать хуки, и все равно выдает ту же ошибку недопустимого вызова хука   -  person Francisco Castillo    schedule 23.07.2020


Ответы (2)


после небольшого изучения я обнаружил, что это не ошибка вашего бандлера (ни веб-пакета, посылки или накопительного пакета). Чтобы решить эту проблему, вам просто нужно опубликовать свою сборку в npm и установить ее оттуда (не локально) и вуаля, она работает. ваше здоровье

person Francisco Castillo    schedule 25.07.2020
comment
Во всяком случае идея, почему это так? Как мы развиваем его локально? - person Kevin Danikowski; 19.01.2021
comment
Это хороший вопрос, и я хотел бы знать ответ на него :) - person dotsa; 20.01.2021

Исключение react и react-dom из devDependencies помогло мне устранить эту ошибку.

person Ihor Golovatskiy    schedule 12.03.2021