Skip to content

How to properly import request.js along with its dependencies in an HTML file for browsers? #109

@armsp

Description

@armsp

I am sorry to be asking this here, but I have not been able to run the codes in the README. I sought help on SO too but I am afraid nothing came of it.  

I have the following html file (sans the api token) -

<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
    <script type="module">
        import { request } from "https://cdn.pika.dev/@octokit/request";
    </script>
    <script>
        const octokitRequest = require('@octokit/request');
        myAsyncMethod()
        async function myAsyncMethod () {
            const result = await request("GET /users/:user/repos", {
                headers: {
                    authorization: "token <your token>"
                },
                user: "armsp"
                });
            console.log(`${result.data.length} repos found.`);
        }
    </script>  
</body>

This is the error I get -  

require.min.js:1 Uncaught Error: Module name "@octokit/request" has not been loaded yet for context: _. Use require([])
https://requirejs.org/docs/errors.html#notloaded
    at makeError (require.min.js:1)
    at Object.s [as require] (require.min.js:1)
    at requirejs (require.min.js:1)
    at github-api-test.html:11

github-api-test.html:1 Uncaught SyntaxError: The requested module '/universal-user-agent/^4.0.0/es2019/universal-user-agent.js' does not provide an export named 'default'

I tried to download the js file itself and include it in script tag the usual way, but I don't see any request.js file in src folder, all are .ts files. I don't know how to make sense of it.

Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: SupportAny questions, information, or general needs around the SDK or GitHub APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions