-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
rollup fails on non-transformed async functions #548
Comments
Looking into this further, thinking comes down to limitation of acorn parser? so maybe need to include and enable this plugin? |
@rustyedges Rollup currently only targets ES6, although it'll likely get extended to ES7 shortly. For now, if you use >ES6 features, they'll need to be transpiled for Rollup to process them. |
@Victorystick thanks for confirming and the work on rollup. I realized I often conflate ES6 and ES7 |
FYI Chrome Canary and Edge Preview has async/await support now. Safari/Webkit will ship it in the next Technical Previews and Firefox is working on this as well. |
Mozilla Firefox, Microsoft Edge, Apple Safari (both macOS and iOS), and the Blink platforms Google Chrome, Opera Browser, and Node have all now shipped built-in async functions to their stable releases. Async functions without transpilation are now available to all modern web browsers and to Node. This issue should be revisited. |
Any update about this? |
I don't think this is an issue in rollup 0.43. Rollup bundles the demo successfully: $ cat a.js
const fn = async () => {
return 'promise me this'
}
(async () => {
const msg = await fn()
console.log(msg)
})()
$ rollup a.js --format iife
(function () {
'use strict';
const fn = async () => {
return 'promise me this'
};
(async () => {
const msg = await fn();
console.log(msg);
})();
}()); Also shown in acorn's own tests: https://github.com/ternjs/acorn/blob/master/test/tests-asyncawait.js @regou can you open a separate issue describing your problem, if any? |
Installing rollup.config.js: import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import pkg from "./package.json";
import async from 'rollup-plugin-async';
const external = [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
];
const makeExternalPredicate = externalArr => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join("|")})($|/)`);
return id => pattern.test(id);
};
export default {
input: 'src/cronreader.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
globals: {
"@babel/runtime/regenerator": "regeneratorRuntime",
"@babel/runtime/helpers/asyncToGenerator": "asyncToGenerator"
}
},
external: makeExternalPredicate(external),
plugins: [
async(),
resolve({
customResolveOptions: {
moduleDirectory: 'src'
}
}),
babel({
runtimeHelpers: true,
exclude: 'node_modules/**', // only transpile our source code
presets: ["@babel/env"],
plugins: [
"@babel/transform-runtime",
"@babel/transform-async-to-generator",
]
})
]
} I was referred to this page from here: https://stackoverflow.com/questions/39902076/babel-rollup-errors-transpiling-and-bundling-es2017/39936968#39936968 |
Without enabling babel plugin (and transpiling with regenerator runtime or transform-async-to-generators), the following simple code will fail to bundle with rollup, throwing unexpected token error...
ran into this issue when trying to build app targeting chakracore. my first step was to replace all import/export with require calls and strip client-side stuff and see it running successfully without bundling on node-chakra (which supports async/await as well)
Guess my understanding was that could use whatever your runtime supported and rollup could handle the bundling/tree shaking of ES6 modules without requiring babel transpilation? Wonder how to track down full list of "next-generation" (ES6/7) language constructs that are supported without plugging in Babel?
The text was updated successfully, but these errors were encountered: