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
Support asynchronous configuration #9888
Comments
Hey @guybedford! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
While developing Babel 7 beta, we added that errors to be able to introduce async config/plugins during the Babel 7 lifetime without breaking changes. The biggest problem is that currently Babel can be called synchronously ( |
Thanks for clarifying. Ok so how can we do this safely? Just throw when running under the sync transform only? |
Either that, or https://github.com/abbr/deasync. I have done some research to understand how hard would be for the ecosystem to support async Babel configurations:
|
When I added the error my intention was to eventually
That way if a plugin really wanted to use It'd also be interesting to continue working to make other implementations async, or at least optionally async. I had thought for instance that |
There seem to be quite a lot of ways to come at this problem. Note also that an alternative way to support the use case mentioned above for jspm would be if Babel would support top-level await in the If I created a tracking issue specifically for top-level await in |
Since we aren't transpiling Also, I think that when plugins will be written using native node esm we will be forced to resolve them asynchronously, since we load them dynamically. |
@nicolo-ribaudo do you mean this is because it is loaded via I think that this can be made to support top-level await with a pattern something like (exact details may be slightly off since I'm writing this in a github comment): function asyncRequire (name) {
const Module = require('module').Module;
const m = new Module(name);
m.paths = Module._nodeModulePaths(path.resolve(name));
const promise = eval(`(async function (exports, require, module, __filename, __dirname) {
${fs.readFileSync(name).toString()};
})(m.exports, m.require, m, __filename, __dirname)`;
return promise;
} |
Or preferably in the above via |
any progress? we really need this feature |
@javadbat Not presently. Would you be able to elaborate on the usecase you are hoping for? Even if we implement this, there will be cases where it is not supported, like with |
I just want to be able to transpile our react app on the fly in browser for each page with systemjs 2 for Dev environment |
Fixed by #12266, it will be released in 7.13.0 |
I couldn't find an existing tracking issue for this feature, please mark as a duplicate if I've missed anything.
This is something that would be required for jspm support in Babel CLI, where we'd want to use dynamic
import()
to reference plugins directly, and so would need some kind of promise support in the configuration.Currently an asynchronous configuration gives the following error:
And an asynchronous plugin gives the following error:
Either or both of these features would be really great to support.
The async plugin case effectively provides parity with top-level await workflows in future too. Happy to discuss further as well.
The text was updated successfully, but these errors were encountered: