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

[BUG/ASK for HELP]: Issues with @octokit/core@v6.0.0+ when using ncc to bundle code #666

Closed
1 task done
jamacku opened this issue Mar 7, 2024 · 6 comments
Closed
1 task done
Labels
Type: Bug Something isn't working as documented

Comments

@jamacku
Copy link

jamacku commented Mar 7, 2024

What happened?

This is probably a very silly beginner issue, but I can't figure out what is wrong. I'm using @octokit/core in most of my GHA and all of then breaks when updating to v6+. I use ncc for compiling TypeScript to single file as suggested in official typescript-action template.

All actions behave exactly the same after updating to v6. The call of ncc fails with:

Error: Module not found: Error: Package path . is not exported from package /home/runner/work/regression-sniffer/regression-sniffer/node_modules/@octokit/core (see exports field in /home/runner/work/regression-sniffer/regression-sniffer/node_modules/@octokit/core/package.json)
Did you mean './@octokit/core'?
Requests that should resolve in the current directory need to start with './'.

Example from one of my actions: https://github.com/redhat-plumbers-in-action/regression-sniffer/actions/runs/8140133727/job/22244735285?pr=50#step:6:8

This can be also 100% reproduce locally:

gh repo clone redhat-plumbers-in-action/regression-sniffer
cd regression-sniffer
yarn update @octokit/core
yarn
yarn run package # or yarn run all

package.json:

{
  "name": "regression-sniffer",
  "version": "1.0.0",
  "private": true,
  "description": "Loyal GitHub action that sniffs out any follow-up and revert commit of your cherry-picked commit",
  "main": "src/main.ts",
  "scripts": {
    "build": "tsc",
    "format": "prettier --write '**/*.ts'",
    "format-check": "prettier --check '**/*.ts'",
    "lint": "eslint src/**/*.ts",
    "package": "ncc build --source-map --license licenses.txt",
    "test": "vitest run --coverage",
    "update-snapshots": "vitest run --update",
    "all": "yarn install && yarn run build && yarn run format && yarn run lint && yarn run package && yarn test"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/redhat-plumbers-in-action/regression-sniffer.git"
  },
  "keywords": [
    "actions",
    "regression-detection",
    "revert",
    "follow-up"
  ],
  "author": "jamacku@redhat.com",
  "license": "MIT",
  "packageManager": "yarn@4.1.1",
  "type": "module",
  "dependencies": {
    "@actions/core": "^1.10.1",
    "@actions/github": "^6.0.0",
    "@octokit/core": "^5.1.0",
    "@octokit/plugin-throttling": "^8.1.3",
    "@probot/octokit-plugin-config": "^2.0.1",
    "deepmerge": "^4.3.1",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@total-typescript/ts-reset": "^0.5.1",
    "@types/node": "^20.11.19",
    "@typescript-eslint/eslint-plugin": "^7.0.2",
    "@typescript-eslint/parser": "^7.0.2",
    "@vercel/ncc": "^0.38.1",
    "@vitest/coverage-v8": "^1.3.1",
    "eslint": "^8.56.0",
    "eslint-plugin-prettier": "^5.1.3",
    "prettier": "^3.2.5",
    "typescript": "^5.3.3",
    "vitest": "^1.3.1"
  }
}

Thank you for any help or suggestions.

Versions

@octokit/core: v6.0.0, v6.0.1
node: v20.11.1
npm: 10.2.4
yarn: 4.1.0

Relevant log output

ncc: Version 0.38.1
ncc: Compiling file index.js into ESM
ncc: Using typescript@5.3.3 (local user-provided)
Error: Module not found: Error: Package path . is not exported from package /home/runner/work/regression-sniffer/regression-sniffer/node_modules/@octokit/core (see exports field in /home/runner/work/regression-sniffer/regression-sniffer/node_modules/@octokit/core/package.json)
Did you mean './@octokit/core'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
    at /home/runner/work/regression-sniffer/regression-sniffer/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:38:1896272
    at /home/runner/work/regression-sniffer/regression-sniffer/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:38:396262
    at _done (eval at create (/home/runner/work/regression-sniffer/regression-sniffer/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:21:75523), <anonymous>:9:1)
    at eval (eval at create (/home/runner/work/regression-sniffer/regression-sniffer/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:21:75523), <anonymous>:34:22)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jamacku jamacku added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Mar 7, 2024
Copy link
Contributor

github-actions bot commented Mar 7, 2024

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@wolfy1339
Copy link
Member

You don't need @octokit/core when using @actions/github

@actions/github requires v5 @octokit/core, which breaks newer @octokit/core versions defined as dependencies

@wolfy1339 wolfy1339 removed the Status: Triage This is being looked at and prioritized label Mar 7, 2024
@wolfy1339
Copy link
Member

Also, I recommend using esbuild instead of ncc as it creates more readable output files, and correctly ouputs ESM, and is much simpler. (From octokit/graphql-action#255 (comment))

Use https://github.com/actions/create-github-app-token/ as a reference

@github-project-automation github-project-automation bot moved this from 🆕 Triage to ✅ Done in 🧰 Octokit Active Mar 7, 2024
@jamacku
Copy link
Author

jamacku commented Mar 7, 2024

@wolfy1339 Thank you for your help! I have removed @octokit/core, and it works as expected.

I'm just a bit confused as to why I'm able to import { Octokit } from '@octokit/core'; without an error.

https://github.com/redhat-plumbers-in-action/regression-sniffer/blob/main/src/octokit.ts#L2

Thank you for suggesting esbuild. I'll have a look.

@wolfy1339
Copy link
Member

wolfy1339 commented Mar 7, 2024

In v6 of @octokit/core we switched to ESM, in v5 we were outputting CJS.

Since you are using plugins, you will have to stick with @octokit/core v5 until @probot/octokit-plugin-config is updated and remove @actions/github

@gr2m
Copy link
Contributor

gr2m commented Mar 7, 2024

Also, I recommend using esbuild instead of ncc as it creates more readable output files, and correctly ouputs ESM, and is much simpler. (From octokit/graphql-action#255 (comment))

I second that. Use esbuild. I used ncc in the past but esbuild is the better tool to bundle code for actions if your source is ESM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
Archived in project
Development

No branches or pull requests

3 participants