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 when trying to import into browser #51

Open
ray73864 opened this issue Aug 22, 2024 · 2 comments
Open

Error when trying to import into browser #51

ray73864 opened this issue Aug 22, 2024 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@ray73864
Copy link

When trying to import into the browser by doing <script src="https://unpkg.com/browse/@rwh/keystrokes@latest/dist/keystrokes.umd.cjs"> I get a 302 redirect and then a 0B file.

If I use the version on jsDelivr via <script src="https://cdn.jsdelivr.net/npm/@rwh/[email protected]/dist/keystrokes.min.js"></script> I get a SyntaxError: Unexpected token 'export' (at keystrokes.min.js:7:11663)

If I use the non-minified version on jsDelivr via <script src="https://cdn.jsdelivr.net/npm/@rwh/[email protected]/dist/keystrokes.js"></script> I get the error SyntaxError: Unexpected token 'export' (at keystrokes.js:486:1)

I would love to use this library as it looks nicer to use than Hotkeys which requires me to setscopes, etc... But so far I've had zero luck getting it to load in the browser.

@RobertWHurst
Copy link
Owner

Hmm, interesting. Apologies for the inconvenience. I assumed the jsdelivr method would work provided it works via NPM, which it does.

If anyone has any suggestions the help would be most appreciated.

@RobertWHurst RobertWHurst added the help wanted Extra attention is needed label Sep 19, 2024
@HaveClassWillCode
Copy link

I'm writing a browser extension and trying out Keystrokes.
Browser extensions have all kind of restrictions.
I can't load external scripts from a CDN, scripts must be local.
I can't use modules.
So I ran into a similar problem.

I've fixed it in an ugly way:
I downloaded the raw https://unpkg.com/browse/@rwh/[email protected]/dist/keystrokes.js file and put it in my project directory, so it's available locally.
The browser extension chokes on the export at the end of the file:

export {
   S as HandlerState,
   _ as KeyComboState,
   P as Keystrokes,
   N as bindKey,
   G as bindKeyCombo,
   ...

so I commented the whole export out, and replaced it with:

const HandlerState = S;
const KeyComboState = _;
const Keystrokes = P;
const bindKey = N;
const bindKeyCombo = G;
...

Ugly, but it works 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants