wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use CJS version of plugin

Xenfo opened this issue · comments

  • Version: 3.0.0
  • Rollup Version: 2.75.3
  • Node Version: 18.1.0

Reproduction

Call Rollup in a CJS project and it will fail because Chalk v5.0.1 (ESM only version) overrides any local version you may install.

@flux-ui/hooks:build: /Users/xenfo/Desktop/Projects/flux-ui/node_modules/rollup-plugin-ts/dist/cjs/index.cjs:141
@flux-ui/hooks:build:     "babel-plugin-minify-replace",
@flux-ui/hooks:build:       ^
@flux-ui/hooks:build: 
@flux-ui/hooks:build: Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/xenfo/Desktop/Projects/flux-ui/node_modules/rollup-plugin-ts/node_modules/chalk/source/index.js from /Users/xenfo/Desktop/Projects/flux-ui/node_modules/rollup-plugin-ts/dist/cjs/index.cjs not supported.
@flux-ui/hooks:build: Instead change the require of index.js in /Users/xenfo/Desktop/Projects/flux-ui/node_modules/rollup-plugin-ts/dist/cjs/index.cjs to a dynamic import() which is available in all CommonJS modules.
@flux-ui/hooks:build:     at Object.newLoader [as .js] (/Users/xenfo/Desktop/Projects/flux-ui/node_modules/pirates/lib/index.js:141:7)
@flux-ui/hooks:build:     at Object.<anonymous> (/Users/xenfo/Desktop/Projects/flux-ui/node_modules/rollup-plugin-ts/dist/cjs/index.cjs:5:13)
@flux-ui/hooks:build:     at Object.newLoader [as .js] (/Users/xenfo/Desktop/Projects/flux-ui/node_modules/pirates/lib/index.js:141:7)
@flux-ui/hooks:build:     at Object.<anonymous> (/Users/xenfo/Desktop/Projects/flux-ui/scripts/build.ts:6:46)
@flux-ui/hooks:build:     at Module._compile (/Users/xenfo/Desktop/Projects/flux-ui/node_modules/pirates/lib/index.js:136:24)
@flux-ui/hooks:build:     at Object.newLoader [as .ts] (/Users/xenfo/Desktop/Projects/flux-ui/node_modules/pirates/lib/index.js:141:7) {
@flux-ui/hooks:build:   code: 'ERR_REQUIRE_ESM'
@flux-ui/hooks:build: }
@flux-ui/hooks:build: 
@flux-ui/hooks:build: Node.js v18.1.0

Expected Behavior

Plugin to work.

Actual Behavior

Plugin throws error.

It seems Chalk only ships an ESM build. In that case, I may have to make it a peer dependency. Thanks for making me aware of it!

This has been fixed by migrating to ansi-colors in place of chalk in v3.0.1