After switching to npm with workspaces from yarn, I can't make rollup work due to a circular dependency in the node libraries. Was working fine prior to switch to npm and an upgrade to node to 16 (from 12 - also tried node 14).
It is a simple cli tool, with the following dependencies in package.json:
"devDependencies": {
"@rollup/plugin-commonjs": "22.0.1",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-typescript": "8.3.3",
"@types/node": "^16.11.9",
"rollup": "2.77.0",
"rollup-plugin-node-externals": "4.1.1",
"tslib": "2.4.0",
"typescript": "4.7.4",
"watch": "1.0.2"
},
"dependencies": {
"commander": "9.4.0",
"execa": "^6.1.0"
}
rollup.config.js is:
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import externals from 'rollup-plugin-node-externals';
export default {
input: 'src/csa.ts',
output: {
dir: 'build',
format: 'cjs',
strict: false,
banner: '#! /usr/bin/env node\n',
},
plugins: [typescript(), commonjs({ transformMixedEsModules: true }), nodeResolve({ preferBuiltins: true }), externals()],
};
result during build is:
src/csa.ts → build...
(!) Circular dependencies
../../node_modules/util/util.js -> ../../node_modules/util/node_modules/inherits/inherits.js -> ../../node_modules/util/util.js
../../node_modules/assert/node_modules/util/util.js -> ../../node_modules/assert/node_modules/inherits/inherits.js -> ../../node_modules/assert/node_modules/util/util.js
created build in 3.6s
and created .js file won't run when attempting to assess function that was circularly referenced:
/Users/me/apps/hrh/csa/packages/cli/build/csa.js:6795
util.inherits(assert.AssertionError, Error);
^
TypeError: util.inherits is not a function
at requireAssert (/Users/me/apps/hrh/csa/packages/cli/build/csa.js:6795:7)
at Object.<anonymous> (/Users/me/apps/hrh/csa/packages/cli/build/csa.js:7231:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47