Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ESM format for config file #147

Open
davidsneighbour opened this issue Apr 28, 2024 · 3 comments
Open

Support ESM format for config file #147

davidsneighbour opened this issue Apr 28, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@davidsneighbour
Copy link

I don't know if this is a bug or maybe a future feature: using a config that is in the ESM format leads to errors:

❯ npm run release

> @davidsneighbour/kollitsch-dev@2024.1.32 release
> npm run release:patch


> @davidsneighbour/kollitsch-dev@2024.1.32 release:patch
> commit-and-tag-version --release-as patch --sign -a -t "v" --releaseCommitMessageFormat "chore(release): v{{currentTag}}" && ./bin/repo/hooks/postrelease

/home/patrick/github.com/davidsneighbour/kollitsch.dev/node_modules/commit-and-tag-version/lib/configuration.js:20
    const jsConfiguration = require(configPath);
                            ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/patrick/github.com/davidsneighbour/kollitsch.dev/.versionrc.js from /home/patrick/github.com/davidsneighbour/kollitsch.dev/node_modules/commit-and-tag-version/lib/configuration.js not supported.
Instead change the require of .versionrc.js in /home/patrick/github.com/davidsneighbour/kollitsch.dev/node_modules/commit-and-tag-version/lib/configuration.js to a dynamic import() which is available in all CommonJS modules.
    at module.exports.getConfiguration (/home/patrick/github.com/davidsneighbour/kollitsch.dev/node_modules/commit-and-tag-version/lib/configuration.js:20:29)
    at Object.<anonymous> (/home/patrick/github.com/davidsneighbour/kollitsch.dev/node_modules/commit-and-tag-version/command.js:153:11) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.12.2

Does the package understand the config in ESM format and if not is it possible to add this as a feature?

@davidsneighbour davidsneighbour added the question Further information is requested label Apr 28, 2024
@amoshydra
Copy link

change .versionrc.js to .versionrc.cjs.

this package support cjs extension

@amoshydra
Copy link

amoshydra commented May 14, 2024

Oops, I have mistook the issue as about "supporting Package type=module environment". My suggestion above isn't that relevant then.

I have checked the source code, mjs is not supported as the config is always imported via require. See:

if (ext === '.js' || ext === '.cjs') {
const jsConfiguration = require(configPath);

I guess this would be a feature request.

Off the top of my head, it will need to use dynamic import to load an ESM config and making the code flow async.

@TimothyJones
Copy link
Member

I agree, I think this is a feature request. It would definitely be good to have the ability to use ESM for the config.

I believe it would (almost) come for free if we upgraded it to typescript, so I'll tag #29

@TimothyJones TimothyJones changed the title ESM format seems not supported? Support ESM format for config file May 14, 2024
@TimothyJones TimothyJones added enhancement New feature or request and removed question Further information is requested labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants