Trying to install a library and run from another project but facing an error #96
-
Using rollup to package a react.js component. The build for rollup is working and fine and it's getting published to npm successfully. node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c --bundleConfigAsCjs When trying to install the library and run it from another react project, it's giving the following error. The github issue (rollup/rollup#487) for this mentions the following fix but it gives the same error. replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify("production"),
}) This is the rollup.config.js file import { nodeResolve } from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import sucrase from "@rollup/plugin-sucrase"
import replace from "@rollup/plugin-replace"
import pkg from "./package.json"
import terser from "@rollup/plugin-terser"
import peerDepsExternal from "rollup-plugin-peer-deps-external"
const packageJson = require("./package.json")
import json from "@rollup/plugin-json"
import ts from "@rollup/plugin-typescript"
import sourceMaps from "rollup-plugin-sourcemaps"
import { builtinModules } from "module"
import { cjsToEsm } from "cjstoesm"
import nodePolyfills from "rollup-plugin-polyfill-node"
import builtins from "rollup-plugin-node-builtins"
import polyfill from "rollup-plugin-polyfill"
import styles from "rollup-plugin-styles"
import { dts } from "rollup-plugin-dts"
import tailwindcss from "tailwindcss"
import postcss from "rollup-plugin-postcss"
import autoprefixer from "autoprefixer"
import globals from "rollup-plugin-node-globals"
import babel from "@rollup/plugin-babel"
import injectProcessEnv from "rollup-plugin-inject-process-env"
// import babel from "@rollup/plugin-babel"
// import copy from "rollup-plugin-copy"
const tailwindConfig = require("./tailwind.config")
const tsInstance = ts({
transformers: [cjsToEsm()],
})
export default [
{
input: "src/index.ts",
output: [
{
file: packageJson.main,
format: "esm",
sourcemap: true,
},
],
globals: {
process: "process",
},
plugins: [
peerDepsExternal(),
nodeResolve({
jsnext: true,
main: true,
module: true,
}),
sourceMaps(),
polyfill(["es6-object-assign/auto"]),
nodePolyfills(),
tsInstance,
json(),
postcss({
extensions: [".scss", ".module.scss", ".css"],
plugins: [autoprefixer(), tailwindcss(tailwindConfig)],
}),
styles({
mode: "inject",
}),
commonjs({
requireReturnsDefault: false,
include: "node_modules/**", // Default: undefined
browser: true,
preferBuiltins: false,
ignoreGlobal: false, // Default: false
sourceMap: false, // Default: true
}),
babel({
babelHelpers: "bundled",
exclude: "node_modules/**",
presets: [["@babel/preset-react", { runtime: "automatic" }]],
}),
replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify("production"),
}),
// injectProcessEnv({
// NODE_ENV: "production",
// }),
terser(),
sucrase({
transforms: ["typescript", "jsx"],
}),
globals(),
builtins(),
],
external: [
...builtinModules,
...Object.keys(pkg.devDependencies),
...Object.keys(pkg.dependencies),
"useSyncExternalStore",
"prop-types",
"react-is",
"@mui/system/colorManipulator",
"@mui/system/createStyled",
],
},
{
input: "dist/cjs/types/src/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "esm" }],
plugins: [dts()],
external: [/\.(sass|scss|css)$/],
},
] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'm not a javascript expert, but you can take a look at what the Aptos wallet adapter does using |
Beta Was this translation helpful? Give feedback.
I'm not a javascript expert, but you can take a look at what the Aptos wallet adapter does using
tsup
for building a react component https://github.com/aptos-labs/aptos-wallet-adapter/tree/main/packages/wallet-adapter-react