我一直试图让下面的教程工作构建自定义 github actionshttps://docs.github.com/en/actions/creating-actions/creating-a-javascript-action。文章指出,如果你不想检查你的 node_modules 文件夹使用 @ vercel / ncc 包将你的代码编译为一个文件。我已经尝试了 NCC 示例在这里https://github.com/vercel/ncc/tree/main/examples/o-world但我得到同样的错误无论我做什么。我得到的错误是这样的:
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'
]
}
我正在使用最新的 GIT 在 Windows 10 上运行最新的 Node,并且无法让它工作。我已经尝试过 bash,powers,移动目录,似乎没有任何工作。下面是我的项目结构:
我的 package.json 看起来像这样:
{
"name": "read-deploy-instructions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "ec \"Error: no test specified\" && exit 1",
"build": "ncc build index.js -o /dist"
},
"keywords": [],
"autr": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.9.0",
"@actions/github": "^5.0.3"
},
"devDependencies": {
"@vercel/ncc": "latest"
}
}
我的 index.js 看起来像这样:
import core from '@actions/core';
import github from '@actions/github';
try {
// `w-to-greet` input defined in action metadata file
const nameToGreet = core.getInput('w-to-greet');
console.log(`Hello ${nameToGreet}!`);
const time = (new Date()).toTimeString();
core.setOutput("time", time);
// Get the JSON webok 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);
}
如果我运行命令:
npm run build
我得到上面显示的错误。我已经看到多个人发布它没有类似的错误,但没有分辨率。有人有什么想法吗?
提前感谢,
在浪费了许多小时之后,我意识到我试图定位的文件被错误地命名。我告诉 NCC 命令寻找“index.js”,但错误地将其命名为“index,js”。重命名文件后,NCC 命令成功地工作,如预期。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(80条)