semantic-release: @semantic-release/npm silently failing in Github actions therefore not publishing package

Current behavior

When running through the Github actions every action passes and the tags and release are made but the package.json version isn’t updated and the package isn’t published.

I’ve got the same setup in another project and everything is working as expected

Expected behavior

I’m expecting to have all the tags and releases working (which they are) and the version number in the package.json updated to latest tag and to be published

Environment

{
  "branches": [
    "+([0-9])?(.{+([0-9]),x}).x",
    "main",
    "next",
    "next-major",
    {
      "name": "beta",
      "prerelease": true
    },
    {
      "name": "alpha",
      "prerelease": true
    }
  ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/github"
  ]
}
  • CI logs:
[5:36:10 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/npm"
[5:36:10 PM] [semantic-release] [@semantic-release/npm] › ℹ  Write version 1.1.0-alpha.4 to package.json in /home/runner/work/my-package/my-package
(node:2296) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/runner/work/my-package/my-package/node_modules/npm/node_modules/chalk/source/index.js
require() of ES modules is not supported.
require() of /home/runner/work/my-package/my-package/node_modules/npm/node_modules/chalk/source/index.js from /home/runner/work/my-package/my-package/node_modules/npm/lib/utils/explain-dep.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/runner/work/my-package/my-package/node_modules/npm/node_modules/chalk/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/home/runner/work/my-package/my-package/node_modules/npm/lib/utils/explain-dep.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2296) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2296) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[5:36:10 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/npm"
[5:36:12 PM] [semantic-release] › ✔  Created tag v1.1.0-alpha.4
[5:36:12 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/npm"
[5:36:12 PM] [semantic-release] [@semantic-release/npm] › ℹ  Publishing version 1.1.0-alpha.4 to npm registry on dist-tag alpha
(node:2322) UnhandledPromiseRejectionWarning: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/runner/work/my-package/my-package/node_modules/npm/node_modules/chalk/source/index.js
require() of ES modules is not supported.
require() of /home/runner/work/my-package/my-package/node_modules/npm/node_modules/chalk/source/index.js from /home/runner/work/my-package/my-package/node_modules/npm/lib/utils/explain-dep.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/runner/work/my-package/my-package/node_modules/npm/node_modules/chalk/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/home/runner/work/my-package/my-package/node_modules/npm/lib/utils/explain-dep.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2322) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2322) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[5:36:12 PM] [semantic-release] [@semantic-release/npm] › ℹ  Published @MyOrg/my-package@1.1.0-alpha.4 to dist-tag @alpha on https://npm.pkg.github.com
[5:36:12 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/npm"
[5:36:12 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/github"
[5:36:12 PM] [semantic-release] [@semantic-release/github] › ℹ  Published GitHub release: https://github.com/MyOrg/my-package/releases/tag/v1.1.0-alpha.4
[5:36:12 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/github"
[5:36:12 PM] [semantic-release] › ℹ  Start step "success" of plugin "@semantic-release/github"
[5:36:16 PM] [semantic-release] [@semantic-release/github] › ℹ  Added comment to issue #5: https://github.com/MyOrg/my-package/pull/5#issuecomment-1010200825
[5:36:18 PM] [semantic-release] [@semantic-release/github] › ℹ  Added labels [ 'released on @alpha' ] to issue #5
[5:36:19 PM] [semantic-release] › ✔  Completed step "success" of plugin "@semantic-release/githu
[5:36:19 PM] [semantic-release] › ✔  Published release 1.1.0-alpha.4 on alpha channel

This is a screen shot of the releases but no the packages been published Screenshot 2022-01-12 at 11 10 33 b"

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

If using Yarn, a workaround is adding

"resolutions": {
    "npm/chalk": "^4.1.2"
},

to your package.json

If using Yarn, a workaround is adding

"resolutions": {
    "npm/chalk": "^4.1.2"
},

to your package.json

note that this fails now if you update npm past 9.7.0. Then your releases fail in the semantic-release/npm prepare step without any output. Took me hours to figure this out.

Does yarn@3 not respect bundled dependencies? 🤔 npm bundles all of our dependencies so references in package.json should not be then used to fetch remote versions of those deps. This seems like a bug with yarn (maybe it’s considered a feature? 🤷🏼‍♂️) if you happen to be using it to manage/install npm (something I would never recommend tbqh)

As far as the “why does it say "*" when the package’s package.json has versions defined?”, the registry response shared is called a “Packument” (ie. Package + Document - old package metadata API ref) & it’s not a 1:1 representation of package.json.

When you specify a dependency that is also specified in bundledDependencies, it’s going to map the version to "*" (ie. signalling to take whatever is in this package). Notably, you don’t actually have to even specify dependencies that you’re going to bundle (ref. https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bundleddependencies); this practice is just a matter of convenience for maintenance/development purposes.

fascinating, let me reach out to the npm team

I have no idea why but by looking at my commit logs this happened when I had yarn version updated via yarn set version stable.

@gr2m got the same error after updating @semantic-release/npm to v9 and semantic-release to v19.0.2 NodeJS version is v16.13.2

+ yarn release
[12:30:48 PM] [semantic-release] › ℹ  Running semantic-release version 19.0.2
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/changelog"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/npm"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/git"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/changelog"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/npm"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "prepare" from "@semantic-release/git"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/npm"
[12:30:48 PM] [semantic-release] › ✔  Loaded plugin "addChannel" from "@semantic-release/npm"
[12:31:00 PM] [semantic-release] › ✔  Run automated release from branch master on repository git@bitbucket.org:rimacautomobili/oem-dashboard-ui-kit.git
[12:31:01 PM] [semantic-release] › ✔  Allowed to push to the Git repository
[12:31:01 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/changelog"
[12:31:01 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/changelog"
[12:31:01 PM] [semantic-release] › ℹ  Start step "verifyConditions" of plugin "@semantic-release/npm"
[12:31:01 PM] [semantic-release] [@semantic-release/npm] › ℹ  Verify authentication for registry https://registry.npmjs.org/
[12:31:01 PM] [semantic-release] [@semantic-release/npm] › ℹ  Wrote NPM_TOKEN to /tmp/1f104be6c96f97b243225876c66e5e30/.npmrc
/opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/explain-dep.js:1
const chalk = require('chalk')
              ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /opt/atlassian/pipelines/agent/build/node_modules/npm/node_modules/chalk/source/index.js from /opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/explain-dep.js not supported.
Instead change the require of index.js in /opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/explain-dep.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/explain-dep.js:1:15)
    at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/explain-eresolve.js:5:49)
    at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/error-message.js:5:20)
    at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/npm/lib/utils/exit-handler.js:4:22)
    at module.exports (/opt/atlassian/pipelines/agent/build/node_modules/npm/lib/cli.js:18:23)
    at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/npm/bin/npm-cli.js:2:25) {
  code: 'ERR_REQUIRE_ESM'
}