I wrote a package with ReactJs, TypeScript and rollup.
and here is my rollup.config
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import external from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import autoprefixer from 'autoprefixer'
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
export default {
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'esm',
sourcemap: true,
},
],
plugins: [
external(),
resolve(),
typescript({ tsconfig: './tsconfig.json' }),
postcss({
extensions: ['.scss'],
extract: false,
modules: {
generateScopedName: '[name]__[local]___[hash:base64:5]',
},
use: [
['sass', {
includePaths: ['node_modules', 'src'],
}],
],
plugins: [
autoprefixer(),
],
}),
terser(),
commonjs({
include: 'node_modules/**',
}),
json(),
],
}
and also here is my package.json of that package
{...
"devDependencies": {
"@apollo/client": "^3.10.8",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.14.11",
"@types/react": "^18.3.3",
"autoprefixer": "^10.4.19",
"axios": "^1.7.2",
"graphql": "^16.9.0",
"graphql-request": "^7.1.0",
"json-to-graphql-query": "^2.2.5",
"postcss": "^8.4.39",
"postcss-modules": "^6.0.0",
"react-cookie": "^7.2.0",
"rollup": "^4.18.1",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-sass": "^1.13.1",
"sass": "^1.77.6",
"tslib": "^2.6.3",
"typescript": "^5.5.3"
},
"dependencies": {
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
},
"peerDependencies": {
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
}
}
when I install the package in another react app that has webpack.config and typescript when I run it I got error
Unhandled Runtime Error
TypeError: util__WEBPACK_IMPORTED_MODULE_2__.TextEncoder is not a constructor
but I don’t use ‘TextEncoder’ in my code, it generated in my built files. But I can’t figure out the problem and fix it . please pay attention that I don’t have any error on build time and I publish my package successfully. I also try fast-text-encoding but it didn’t help so I removed