Issue in creating Library in React

24 views Asked by At

I am not sure what is issue in this library but this library is not working. Code is working fine in library it self but if I am using it in main app then nothing works. Please let me know if any config have issue.

//Rollup.config.js
import babel from '@rollup/plugin-babel';
import external from 'rollup-plugin-peer-deps-external';
import del from 'rollup-plugin-delete';
import pkg from './package.json';
import postcss from 'rollup-plugin-postcss'
import builtins from 'rollup-plugin-node-builtins';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export default {
    input: pkg.source,
    output: [
        { file: pkg.main, format: 'cjs' },
        { file: pkg.module, format: 'esm' },
        { file: 'bundle.js', format: 'iife' }
    ],
    plugins: [
        external(),
        builtins(),
        nodeResolve(),
        commonjs({exclude: 'src/**'}),
        babel({
            exclude: 'node_modules/**',
            babelHelpers: 'bundled' 
        }),
        del({ targets: ['dist/*'] }),
        postcss({
            autoModules: true,
            plugins: [],
            sourceMap: true,
            extract: true,
            minimize: true,
          })
    ],
    external: Object.keys(pkg.peerDependencies || {}),
};

//package.json

"dependencies": {
    "@rollup/plugin-commonjs": "^25.0.7",
    "@rollup/plugin-node-resolve": "^15.2.3",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "bootstrap": "^5.3.0",
    "crypto-js": "^4.1.1",
    "jsencrypt": "^3.3.2",
    "react-bootstrap": "^2.7.4",
    "react-scripts": "5.0.1",
    "rollup-plugin-node-builtins": "^2.1.2",
    "rollup-plugin-postcss": "^4.0.2",
    "web-vitals": "^2.1.4"
  },
 "devDependencies": {
    "@babel/cli": "^7.21.5",
    "@babel/core": "^7.22.1",
    "@babel/preset-env": "^7.22.4",
    "@babel/preset-react": "^7.22.3",
    "@rollup/plugin-babel": "^6.0.3",
    "npm-run-all": "^4.1.5",
    "rollup": "^2.79.1",
    "rollup-plugin-delete": "^2.0.0",
    "rollup-plugin-peer-deps-external": "^2.2.4"
  },
  "peerDependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }

Logs: enter image description here

Browser Console from Main app where this library is in use enter image description here

0

There are 0 answers