-
Notifications
You must be signed in to change notification settings - Fork 418
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
ISSUE - Requiring a file containing an export #1717
Comments
@derjanb do you know if there is a workaround? |
There is just no way to use ES modules in userscripts. The best you can do is to use dynamic import: (async function() {
'use strict';
const firebase = await import("https://www.gstatic.com/firebasejs/9.17.1/firebase-app.js");
console.log("Tampermonkey: \"Firebase Implementation Exemple\" script start", firebase);
})(); Another way is to build Firebase locally as UMD and host somewhere. |
Good idea! That was fast. :-) Thanks. @Malix-Off
Please use webpack as explained here to bundle your script. or manually add a script tag. This however makes your code completely public to the page and works on pages with no CSP only! // ==UserScript==
// @name Firebase Implementation Example
// @version 1.0.0
// @description Firebase Implementation Example
// @author -
// @match https://example.com/*
// @grant GM_addElement
// ==/UserScript==
const s = GM_addElement('script', { textContent: `
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
window.initializeApp = initializeApp;
runOnLoad();
`, type: 'module' });
unsafeWindow.runOnLoad = () => console.log(unsafeWindow.initializeApp); |
Hello again @derjanb and @7nik and thanks you both for your answer, the dynamic import workaround did the trick. @derjanb, from your comment i tried to bundle it with this guide, but i didn't found a workaround to make it work for an userscript unfortunately |
How exactly have you made the bundle? I had a really good experience using vite-plugin-monkey to develop and build a userscript (TS + Svelte in my case) |
Hello again! I'm currently doing the same thing now ahah, thanks for your advices <3 |
Problem
Requiring a file containing an export causes an "
Unexpected token 'export'
" errorThe userscript is not even running after it.
Exemple
Requiring the firebase-app.js v9 files such as the firebase-app.js v9.17.1 file
The text was updated successfully, but these errors were encountered: