I have built an npm package using Rollup, but after publishing and installing it in another project, I get the following error when running the project:
TypeError: Unable to determine current node version
My Rollup Configuration:
Here is my rollup.config.js:
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import url from "@rollup/plugin-url";
import svgr from "@svgr/rollup";
import jsx from "acorn-jsx";
import dts from "rollup-plugin-dts";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import { terser } from "rollup-plugin-terser";
import { visualizer } from "rollup-plugin-visualizer";
const packageJson = require("./package.json");
export default [
{
input: packageJson.source,
output: [
{
file: packageJson.main,
format: "cjs",
exports: "named",
inlineDynamicImports: true,
},
{
file: packageJson.module,
format: "esm",
inlineDynamicImports: true,
},
],
acornInjectPlugins: [jsx()],
plugins: [
peerDepsExternal(),
json(),
url({
include: ["**/*.svg", "**/*.png"],
limit: 8192,
emitFiles: true,
fileName: "[dirname][hash][extname]",
}),
svgr(),
resolve({
extensions: [".js", ".jsx", ".ts", ".tsx"],
mainFields: ["module", "main"],
preferBuiltins: false,
browser: true,
}),
babel({
exclude: "node_modules/**",
babelHelpers: "runtime",
extensions: [".js", ".ts", ".jsx", ".tsx"],
presets: ["@babel/preset-react", "@babel/preset-typescript"],
plugins: ["@babel/plugin-transform-runtime"],
}),
commonjs({
include: "node_modules/**",
exclude: [
"node_modules/process-es6/**",
"node_modules/@mui/**",
"node_modules/three/**",
],
}),
typescript({
tsconfig: "./tsconfig.json",
exclude: ["**/*.stories.tsx", "**/*.test.tsx"],
}),
postcss({
extract: true,
minimize: true,
modules: true,
plugins: [require("cssnano")], // Add CSS minification
}),
terser({
format: {
comments: false,
},
compress: {
drop_console: true,
ecma: 2015,
},
}),
visualizer({
filename: "bundle-analysis.html",
open: true,
}),
],
external: [
/^react($|/)/,
/^react-dom($|/)/,
/^three($|/)/,
/^@mui/.*/,
/^@react-three/.*/,
"axios",
"jszip",
"i18next",
"react-i18next",
"lucide-react",
"moment",
"process",
],
},
{
input: "build/types/index.d.ts",
output: [{ file: "build/index.d.ts", format: "esm" }],
plugins: [dts.default()],
external: [/.css$/, /.scss$/],
},
];
Package.json
My package.json includes:
{
"name": "@solarhub-3d-viewer",
"version": "0.0.10",
"main": "build/index.js",
"module": "build/index.es.js",
"types": "dist/index.d.ts",
"source": "index.ts",
"dependencies": {
"@babel/preset-flow": "^7.25.9",
"@cometchat-pro/chat": "^3.0.6",
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@mui/icons-material": "^5.5.1",
"@mui/material": "^5.14.17",
"@mui/styles": "^5.5.3",
"@mui/types": "^7.1.3",
"@react-google-maps/api": "^2.19.2",
"@react-oauth/google": "^0.10.0",
"@react-pdf/renderer": "^3.4.4",
"@react-three/drei": "^9.109.5",
"@react-three/fiber": "^8.17.5",
"@rollup/plugin-babel": "^6.0.4",
"@sentry/react": "^7.27.0",
"@sentry/tracing": "^7.27.0",
"@stripe/react-stripe-js": "^1.7.0",
"@stripe/stripe-js": "^1.24.0",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"@turf/turf": "^6.5.0",
"@types/antd": "^1.0.0",
"@types/axios": "^0.14.0",
"@types/jest": "^27.4.1",
"@types/mapbox__mapbox-gl-geocoder": "^4.7.2",
"@types/mixpanel-browser": "^2.38.0",
"@types/node": "^16.11.26",
"@types/react-dom": "^17.0.13",
"@types/react-dropzone": "^5.1.0",
"@types/react-share": "^4.0.0",
"@types/styled-components": "^5.1.24",
"@types/uuid": "^8.3.4",
"antd": "^4.19.2",
"apexcharts": "^3.36.0",
"axios": "^0.26.1",
"buffer": "^6.0.3",
"chart.js": "^3.9.1",
"dateformat": "^4.6.3",
"earcut": "^2.2.4",
"emoji-mart": "^3.0.1",
"env-cmd": "^10.1.0",
"firebase": "^8.4.2",
"firebase-admin": "^10.0.0",
"geofire-common": "^5.2.0",
"geotiff": "^2.1.3",
"geotiff-geokeys-to-proj4": "^2024.4.13",
"html-react-parser": "^1.4.5",
"html-to-image": "^1.11.11",
"html2canvas": "^1.4.1",
"http": "0.0.1-security",
"https": "^1.0.0",
"https-browserify": "^1.0.0",
"i": "^0.3.7",
"i18next": "^21.8.16",
"install": "^0.13.0",
"jodit-react": "^4.1.2",
"jszip": "^3.10.1",
"jwt-decode": "^4.0.0",
"load-bmfont": "^1.4.1",
"lodash": "^4.17.21",
"lucide-react": "^0.469.0",
"mapbox-gl": "^2.7.1",
"mixpanel-browser": "^2.45.0",
"ndarray": "^1.0.19",
"ndarray-gemm": "^1.0.0",
"npm": "^8.7.0",
"pdf-lib": "^1.17.1",
"plotty": "^0.4.9",
"proj4": "^2.11.0",
"prop-types": "^15.8.1",
"querystring": "^0.2.1",
"react": "^18.3.1",
"react-3d-viewer": "^1.0.12",
"react-apexcharts": "^1.4.0",
"react-app-rewired": "^2.2.1",
"react-calendly": "^2.2.2",
"react-chartjs-2": "^4.3.1",
"react-colorful": "^5.6.1",
"react-dom": "^18.3.1",
"react-draggable": "^4.4.6",
"react-dropzone": "^14.2.2",
"react-full-screen": "^1.1.1",
"react-html-parser": "^2.0.2",
"react-i18next": "^11.18.6",
"react-image-gallery": "^1.2.7",
"react-map-gl": "^6.1.16",
"react-map-gl-geocoder": "^2.1.7",
"react-mapbox-gl-geocoder": "^1.1.0",
"react-multi-date-picker": "^3.3.0",
"react-pdf": "^9.1.0",
"react-query": "^3.34.16",
"react-quick-pinch-zoom": "^4.9.0",
"react-redux": "^7.2.6",
"react-router": "^6.18.0",
"react-router-dom": "^6.2.2",
"react-scripts": "^5.0.0",
"react-share": "^4.4.0",
"react-signature-canvas": "^1.0.6",
"react-slick": "^0.28.1",
"react-spinners": "^0.11.0",
"react-timezone-select": "^1.2.0",
"react-to-print": "^2.15.1",
"react-toastify": "^8.2.0",
"redux": "^4.1.2",
"redux-saga": "^1.1.3",
"redux-thunk": "^2.4.1",
"reselect": "^4.1.8",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dts": "^6.1.1",
"slick-carousel": "^1.8.1",
"stream-http": "^3.2.0",
"suncalc": "^1.9.0",
"swiper": "^6.8.4",
"three": "^0.167.1",
"three-bmfont-text": "^3.0.1",
"twemoji": "^13.1.0",
"url": "^0.11.0",
"uuid": "^8.3.2",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "env-cmd -f .env.stage react-app-rewired start",
"prebuild": "tsc --noEmit",
"build": "env-cmd -f .env.stage react-app-rewired build",
"deploy": "firebase deploy --only hosting:solarhub-redesign",
"start:prod": "env-cmd -f .env.prod react-app-rewired start",
"prebuild:prod": "tsc --noEmit",
"build:prod": "env-cmd -f .env.prod react-app-rewired build",
"predeploy:prod": "npm run build:prod",
"deploy:prod": "firebase deploy --only hosting:solarhub-44450",
"lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
"lint:fix": "eslint --fix 'src/**/*.{js,jsx,ts,tsx,json}'",
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"rollup": "rollup -c --bundleConfigAsCjs"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.26.9",
"@babel/preset-react": "^7.26.3",
"@babel/runtime": "^7.26.9",
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-typescript": "^12.1.2",
"@rollup/plugin-url": "^8.0.2",
"@svgr/rollup": "^8.1.0",
"@types/earcut": "^2.1.4",
"@types/lodash": "^4.14.182",
"@types/mapbox-gl": "^2.6.3",
"@types/ndarray": "^1.0.11",
"@types/proj4": "^2.5.5",
"@types/react": "^17.0.19",
"@types/react-html-parser": "^2.0.2",
"@types/react-signature-canvas": "^1.0.5",
"@types/react-slick": "^0.23.8",
"@types/suncalc": "^1.9.2",
"@types/three": "^0.158.3",
"@typescript-eslint/eslint-plugin": "^5.47.1",
"ajv": "^7.2.4",
"autoprefixer": "^10.4.2",
"cssnano": "^7.0.6",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^24.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"i18next-scanner": "^4.3.0",
"postcss": "^8.4.8",
"prettier": "^2.8.1",
"process": "^0.11.10",
"readline-sync": "^1.4.10",
"rollup": "^4.34.9",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.14.0",
"styled-components": "^5.3.3",
"tailwindcss": "^3.0.23",
"ts-node": "^10.9.2",
"typescript": "^5.8.2"
}
}
My config.overrides.js:
const webpack = require("webpack");
module.exports = function override(config, env) {
config.resolve.fallback = {
...config.resolve.fallback,
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
buffer: require.resolve("buffer"),
assert: require.resolve("assert/"),
tty: require.resolve("tty-browserify"),
util: require.resolve("util/"),
os: require.resolve("os-browserify/browser"),
path: require.resolve("path-browserify"),
"process": require.resolve("process/browser"),
fs: false, // fs is not available in browsers
module: false, // module should not be included
};
config.resolve.extensions = [...config.resolve.extensions, ".ts", ".js"];
config.plugins = [
...config.plugins,
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
];
config.module.rules.push({
test: /.(js|mjs|jsx)$/,
enforce: "pre",
loader: require.resolve("source-map-loader"),
resolve: {
fullySpecified: false,
},
});
return config;
};
What I Have Tried:
- Ensured the package.json correctly specifies source, main, and
module.
- Checked if babelHelpers: “runtime” is correctly configured.
- Added preferBuiltins: false in @rollup/plugin-node-resolve.
- Verified that external dependencies are properly marked in external.
Additional Info:
- Node.js Version: v16.14.0
- Project Type: React + TypeScript
- Error Appears When: Running the installed package inside another project
Question:
What could be causing this error, and how can I fix it? Any help would be greatly appreciated! Let me know if you have any questions!