Home > Enterprise >  Getting Error: Cannot find module '../lib/cli.js' when running @semantic-release/npm plugi
Getting Error: Cannot find module '../lib/cli.js' when running @semantic-release/npm plugi

Time:11-14

I have the following Github action step which by design should do semantic release and at the end update "version" field in package.json but failed with error below.

I tried to use all the latest version but error remains, any ideas?

semantic-versioning:
if: inputs.infra_dir != 'prod'
runs-on: ${{ inputs.runs_on }}
steps:
  - name: ⤵️  Checkout repo
    uses: actions/checkout@v3
  - name: "⚙️ Setup Node"
    uses: actions/setup-node@v3
    with:
      node-version: "16"
  - name: Action For Semantic Release
    uses: cycjimmy/[email protected]
    with:
      semantic_version: 19.0.5
      branch: "main"
      extra_plugins: |
        @semantic-release/changelog@6
        @semantic-release/git
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json:

{
"name": "app",
"version": "0.1.0",
"release": {
    "branches": ["master", "main", "SemVer"],
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        ["@semantic-release/npm", 
          {
            "npmPublish": false
          }
        ],
        [
          "@semantic-release/changelog",
          {
            "changelogFile": "docs/CHANGELOG.md"
          }
        ],
        [
          "@semantic-release/git",
          {
            "assets": ["docs/CHANGELOG.md"]
          }
        ]
      ]
  }

}

The log and the error Error: Cannot find module '../lib/cli.js' at line #63

Acquiring 16.18.0
[semantic-release] [@semantic-release/npm] › ℹ  Write version 1.1.0 to package.json in /home/ec2-user/actions-runner/_work/test
59 node:internal/modules/cjs/loader:936
60 throw err;
63 Error: Cannot find module '../lib/cli.js'
64 Require stack:
65 - /home/ec2-user/actions-runner/externals.2.299.1/node16/bin/npm
66 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
67 at Function.Module._load (node:internal/modules/cjs/loader:778:27)
68 at Module.require (node:internal/modules/cjs/loader:1005:19)
69 at require (node:internal/modules/cjs/helpers:102:18)
70 at Object.<anonymous> (/home/ec2-user/actions runner/externals.2.299.1/node16/bin/npm:2:1)
71 at Module._compile (node:internal/modules/cjs/loader:1101:14)
72 at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
73 at Module.load (node:internal/modules/cjs/loader:981:32)
74 at Function.Module._load (node:internal/modules/cjs/loader:822:12)
75 at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
76 code: 'MODULE_NOT_FOUND',
77 requireStack: [ '/home/ec2-user/actions-runner/externals.2.299.1/node16/bin/npm' ]
78 }
79 [7:07:42 AM] [semantic-release] › ✖  Failed step "prepare" of plugin "@semantic-release/npm"
80 [7:07:42 AM] [semantic-release] › ✖  An error occurred while running semantic-release: Error: Command failed with exit code 1: npm version 1.1.0 --userconfig /tmp/5959228743ee200b6bb8b24654dabd8f/.npmrc --no-git-tag-version --allow-same-version
81 node:internal/modules/cjs/loader:936

CodePudding user response:

I updated the template.yml with the following to match with what's in the package.json and it seems to be working in terms of the pipeline:

        extra_plugins: |
        @semantic-release/commit-analyzer
        @semantic-release/release-notes-generator
        @semantic-release/[email protected]
        @semantic-release/changelog@6                        
        @semantic-release/git

but I didn't see version inside package.json gets updated although with the following log:

[10:55:16 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/npm"
[10:55:16 PM] [semantic-release] [@semantic-release/npm] › ℹ  Write version 1.1.0 to package.json in /home/ec2-user/actions-runner/_work/test
v1.1.0
[10:55:16 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/npm"

CodePudding user response:

I'm answering my question again.

I have to add the following after the npm plugin to make it update version in package.json. Same with changelog plugin.

            [
            "@semantic-release/git",
            {
                "assets": [
                    "package.json"
                ]
            }
        ],
  • Related