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

error with universal user agent in the new actions #102

Closed
inlife opened this issue Sep 18, 2019 · 7 comments
Closed

error with universal user agent in the new actions #102

inlife opened this issue Sep 18, 2019 · 7 comments

Comments

@inlife
Copy link

inlife commented Sep 18, 2019

Hello,

I've been trying to use the new @actions/github, which allows me to create a new octokit instance and call various api methods. I've been attempting to use release apis.

The custom action i'm using is a local action, stored inside the repository.
An attempt to use the action triggers an error:

Run ./.github/actions/release-upload
/Users/runner/runners/2.157.5/work/myproject/.github/actions/release-upload/node_modules/@octokit/endpoint/dist-node/index.js:360
const userAgent = `octokit-endpoint.js/${VERSION} ${universalUserAgent.getUserAgent()}`;
                                                                       ^

TypeError: universalUserAgent.getUserAgent is not a function
    at Object.<anonymous> (/Users/runner/runners/2.157.5/work/myproject/.github/actions/release-upload/node_modules/@octokit/endpoint/dist-node/index.js:360:72)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/runner/runners/2.157.5/work/myproject/.github/actions/release-upload/node_modules/@octokit/request/dist-node/index.js:7:16)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
##[error]Node run failed with exit code 1

Now, seems to me that the error is caused by the fact that the "compiled" js version of the package universal-user-agent has main pointing to the file that actually returns a function, rather than an object.

part of universal-user-agent's package.json (inside node_modules for @octokit/endpoint):

  ...
  "homepage": "https://github.com/gr2m/universal-user-agent#readme",
  "keywords": [],
  "license": "ISC",
  "main": "dist-node/index.js",
  "module": "dist-web/index.js",
  "name": "universal-user-agent",
  "pika": true,
  ...

Also that issue seems to be related to the gr2m/universal-user-agent#23

Thank you!

@gr2m
Copy link
Contributor

gr2m commented Sep 18, 2019

I'm not sure what you mean with compiled? Do you have a build step for your code before it gets run in the action? That might be the problem, as gr2m/universal-user-agent#23 has a "module" field which currently points to the version of the library that is meant for browsers, not Node. I do not know how to address this problem at this point. I use https://github.com/pikapkg/pack (which is using Rollup internally) for building the different versions, maybe a plugin (see https://github.com/pikapkg/builders) could be created which somehow creates another field in the package.json file that makes this work? I wouldn't know how though, I've reached out to the Pika folks but no response yet

@gr2m
Copy link
Contributor

gr2m commented Sep 18, 2019

Could you try to import universal-user-agent/dist-src/node? That would give you this file:
https://unpkg.com/browse/universal-user-agent@4.0.0/dist-src/node.js

@inlife
Copy link
Author

inlife commented Sep 18, 2019

by compiled I mean rather transpiled from typescript to js

@inlife
Copy link
Author

inlife commented Sep 18, 2019

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var osName = _interopDefault(require('os-name'));

function getUserAgent() {
  try {
    return `Node.js/${process.version.substr(1)} (${osName()}; ${process.arch})`;
  } catch (error) {
    if (/wmic os get Caption/.test(error.message)) {
      return "Windows <version undetectable>";
    }

    throw error;
  }
}

exports.getUserAgent = getUserAgent;
//# sourceMappingURL=index.js.map

@inlife
Copy link
Author

inlife commented Sep 18, 2019

Do you have a build step for your code before it gets run in the action?

No, I do not. I'm actually not sure on how to introduce it for a local (not external) action.

@inlife
Copy link
Author

inlife commented Sep 19, 2019

I used approach of commiting and pushing my action with the node_modules folder to the remote. Even tho even I consider it to be a bit wrong.

https://help.github.com/en/articles/creating-a-javascript-action#commit-and-push-your-action-to-github

However, when I tried a different recommended approach (using ncc) to "precompile" a single js and commit that file, instead of the default, that helped, and it all worked out.

@inlife inlife closed this as completed Sep 19, 2019
@gr2m
Copy link
Contributor

gr2m commented Sep 19, 2019

Thanks for letting us know 👍 Glad to hear that you got it working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants