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

Can almond be forced to require synchronously? #123

Open
ca0v opened this issue Mar 15, 2020 · 0 comments
Open

Can almond be forced to require synchronously? #123

ca0v opened this issue Mar 15, 2020 · 0 comments

Comments

@ca0v
Copy link

ca0v commented Mar 15, 2020

I am wanting to develop modular service workers and I would like to continue using typescript and AMD modules to do it:

declare var requirejs: Function;
self.importScripts("../static/almond.js");
requirejs(["serviceworker/index"], (worker: { run: (worker:any) => void }) => worker.run(self));

The above results in the following error:

Event handler of 'fetch' event must be added on the initial evaluation of worker script.

The problem, I think, is the setTimout in following code in almond.js:

        //Simulate async callback;
        if (forceSync) {
            main(undef, deps, callback, relName);
        } else {
            setTimeout(function () {
                main(undef, deps, callback, relName);
            }, 4);
        }

I tried forcing forceSync to be true but ran into other problems. All the modules are in one concatenated filed thanks to the typescript compilers "outfile" option. Any guidence of possible code changes to allow almond to be used as a service worker loader?

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

1 participant