semantic-release-plus / semantic-release

:package::rocket: Fully automated version management and package publishing
https://semantic-release-plus.gitbook.io
MIT License
48 stars 4 forks source link

Time to upgrade again - semantic-release is now ESM :/ #292

Open kf6kjg opened 1 year ago

kf6kjg commented 1 year ago

The base repo has converted to ESM. This is causing me some headaches:

  1. My config file is TS that's compiled to JS. The only TypeScript types that exist are for @types/semantic-release which exports as ESM.
  2. SRP is still CommonJS and thus fails with the following error:
An error occurred while running semantic-release: Error [ERR_REQUIRE_ESM]: require() of ES Module /__w/libraries/libraries/packages/eslint-config/.releaserc.mjs not supported.
    root: Instead change the require of /__w/libraries/libraries/packages/eslint-config/.releaserc.mjs to a dynamic import() which is available in all CommonJS modules.
    root:     at /__w/libraries/libraries/node_modules/semantic-release-plus/lib/get-config.js:30:32
    root:     at Array.reduce (<anonymous>)
    root:     at module.exports (/__w/libraries/libraries/node_modules/semantic-release-plus/lib/get-config.js:29:33)
    root:     at async module.exports (/__w/libraries/libraries/node_modules/semantic-release-plus/index.js:357:34)
    root:     at async module.exports (/__w/libraries/libraries/node_modules/semantic-release-plus/cli.js:102:5) {
    root:   code: 'ERR_REQUIRE_ESM'
    root: }
    root: Error [ERR_REQUIRE_ESM]: require() of ES Module /__w/libraries/libraries/packages/eslint-config/.releaserc.mjs not supported.
    root: Instead change the require of /__w/libraries/libraries/packages/eslint-config/.releaserc.mjs to a dynamic import() which is available in all CommonJS modules.
    root:     at /__w/libraries/libraries/node_modules/semantic-release-plus/lib/get-config.js:30:32
    root:     at Array.reduce (<anonymous>)
    root:     at module.exports (/__w/libraries/libraries/node_modules/semantic-release-plus/lib/get-config.js:29:33)
    root:     at async module.exports (/__w/libraries/libraries/node_modules/semantic-release-plus/index.js:357:34)
    root:     at async module.exports (/__w/libraries/libraries/node_modules/semantic-release-plus/cli.js:102:5) {
    root:   code: 'ERR_REQUIRE_ESM'
    root: }

There are some possible workarounds:

  1. Convert to CommonJS and use TypeScript import assertions - an ugly workaround, and currently requires the TS nightly build.
  2. Convert to CommonJS and tell TS to forget about it via // eslint-disable-next-line @typescript-eslint/ban-ts-comment and // @ts-ignore next just before the import of the types from semantic-release. This is what I'm going with ATM to get pas this issue.
  3. Write the config file in raw JS. Eww. No. Been there, fought the bugs.

I'm using JS config files to help support a home-brewed merging "extends" functionality from a central config that really helped with centralizing my release config without compromising the per-package needs.