Cannot Get @Vercel/Ncc Working Throws Module Not Found Error

Cannot Get @Vercel/Ncc Working Throws Module Not Found Error

I have been trying to get the following tutorial working for building custom github actions . The article states that if you don't want to check in your node_modules folder to use @vercel/ncc package to compile your code into a single file. I have tried the NCC sample here but I get the same error no matter what I do. The error I get is this:

Error: Cannot find module 'C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\index.js'
Require stack:
- C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc\cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at resolve (node:internal/modules/cjs/helpers:108:19)
    at runCmd (C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc/cli.js.cache.js:1:52001)
    at Object.819 (C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc/cli.js.cache.js:1:48838)
    at __webpack_require__ (C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc/cli.js.cache.js:1:59074)
    at C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc/cli.js.cache.js:1:59286
    at C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc/cli.js.cache.js:1:59347
    at Object.<anonymous> (C:\Projects\github-runner-test\.github\actions\read-deploy-instructions\node_modules\@vercel\ncc\dist\ncc\cli.js:8:28)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Projects\\github-runner-test\\.github\\actions\\read-deploy-instructions\\node_modules\\@vercel\\ncc\\dist\\ncc\\cli.js'
  ]
}

I am running latest Node on Windows 10 with latest GIT and cannot get this to work at all. I have tried bash, powershell, moved directories around and nothing seems to work. Below is my project structure:

My package.json looks like this:

{
  "name": "read-deploy-instructions",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "ncc build index.js -o /dist"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@actions/core": "^1.9.0",
    "@actions/github": "^5.0.3"
  },
  "devDependencies": {
    "@vercel/ncc": "latest"
  }
}

My index.js looks like this:

import core from '@actions/core';
import github from '@actions/github';

try {
  // `who-to-greet` input defined in action metadata file
  const nameToGreet = core.getInput('who-to-greet');
  console.log(`Hello ${nameToGreet}!`);
  const time = (new Date()).toTimeString();
  core.setOutput("time", time);
  // Get the JSON webhook payload for the event that triggered the workflow
  const payload = JSON.stringify(github.context.payload, undefined, 2)
  console.log(`The event payload: ${payload}`);
} catch (error) {
  core.setFailed(error.message);
}

If I run the command:

npm run build

I get the error shown above. I have seen multiple people posting it doesn't work with similar errors but no resolution. Does anyone have any ideas?

Thanks in advance,

1 Answer

OK after many a wasted hour I realized the file I was trying to target was named incorrectly. I was telling the NCC commands to look for "index.js" but had mistakenly named it "index,js". After renaming the file the NCC commands worked successfully and as expected.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.