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

fix: module export #148

Merged
merged 2 commits into from
Jan 23, 2024
Merged

fix: module export #148

merged 2 commits into from
Jan 23, 2024

Conversation

solaris007
Copy link
Contributor

The current version 8.0.0 does not work in an ESM environment:

solaris007 added a commit to adobe/spacecat-shared that referenced this pull request Jan 22, 2024
Add custom-built semantic-release-monorepo (PR opened here
pmowrer/semantic-release-monorepo#148) to
support ESM.

Using custom build published from here for the time being:
https://github.com/solaris007/semantic-release-monorepo/tree/fix-esm-module
@pmowrer
Copy link
Owner

pmowrer commented Jan 22, 2024

type is not set to module in package.json

I thought it wasn't needed but will try again

src/index.js does not export module style (it can, now that semantic-release/semantic-release#3037 is closed

I don't believe this is strictly required for ESM? It would require a breaking change since it requires a more current version of semantic-release than is currently defined in peer deps.

@solaris007
Copy link
Contributor Author

@pmowrer, not having a type property in the package.json will cause the following warning:

> npx --no-install -ws semantic-release -e semantic-release-monorepo

[9:41:46 AM] [semantic-release] › ℹ  Running semantic-release version 23.0.0
(node:2309) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)

I guess it can be technically ignored but should be curbed nonetheless.

I don't believe this is strictly required for ESM? It would require a breaking change since it requires a more current version of semantic-release than is currently defined in peer deps.

Unfortunately semantic-release-monorepo breaks with semantic-release >= 20 for exactly the above reason. Here's the error:

[9:41:46 AM] [semantic-release] › ✘  An error occurred while running semantic-release: /home/runner/work/***/***/node_modules/semantic-release-monorepo/src/index.js:1
import readPkg from 'read-pkg';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
/home/runner/work/***/***/node_modules/semantic-release-monorepo/src/index.js:1
import readPkg from 'read-pkg';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
Error: Process completed with exit code 1.

The above is fixed by making index.js export ESM-style.

We'll have to find a way to support the latest versions of semantic-release.

Supporting ESM required the following fix released in `semantic-release` 22.0.7:

semantic-release/semantic-release#3037
@pmowrer pmowrer merged commit dbf89dc into pmowrer:master Jan 23, 2024
2 checks passed
Copy link

🎉 This PR is included in version 8.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@solaris007 solaris007 deleted the fix-esm-module branch January 23, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants