moving typescript to end of plugins array solves circular dependency and stability issues - add to docs and warn
- Rollup Plugin Name: @rollup/plugin-typescript
- Rollup Plugin Version: 8.3.3.
Feature Use Case
While maintaining a cli I encountered a puzzling error after switching package managers and upgrading node.
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
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()],
};
After much time spent trying many fixes, I discovered that moving typescript() to the end of the plugins array resolved the issue.
Feature Proposal
Assuming the above is not a bug (is it?), then it would have been great for rollup to give a warning like "typescript should be at the end of the plugins array". And the docs should state that, if it is indeed the case.
Happy to review a PR with the changes you'd like to see.
Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it. ⓘ