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
@babel/runtime -> SyntaxError: Unexpected token export -> helpers/esm/extends #11470
Comments
Hey @ashuorg! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
The |
yes you are right it is not esm related issue i should edit the question following is the logs of
Note: application structure is like following
child package.json [following contains all babel related packages]
|
@ashuorg I've been running into this issue too - were you able to find a fix? |
I've also just hit this issue. Very interested to know if there is fix. |
Use babel 7 and do not disable modules transpiling (commonjs is default). |
Hi @TrySound, I am using babel 7 already, but I don't know what you mean by "do not disable modules transpiling". I'm attempting to build a library for importing into other projects, so I only want to bundle the library code, and have all dependencies, including those added by babel transforms, treated as externals. Note: I am using version My (simplified) rollup config is: const babel = require('rollup-plugin-babel')
const commonjs = require('rollup-plugin-commonjs')
const nodeResolve = require('rollup-plugin-node-resolve')
const pkg = require('./package.json')
const externalList = [
'core-js',
'@babel/runtime',
'regenerator-runtime',
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]
const external = new RegExp(`^(${ externalList.join('|') })($|/)`)
module.exports = {
input: 'src/index.js',
output: [
{ format: 'es', file: 'es/index.js' },
{ format: 'cjs', file: 'lib/index.js', exports: 'named' },
],
external: id => external.test(id)
plugins: [
babel({
exclude: /node_modules/,
runtimeHelpers: true,
externalHelpers: false,
extensions: ['.js', '.jsx'],
}),
commonjs({ include: /node_modules/ }),
nodeResolve({
extensions,
mainFields: ['module', 'main'],
}),
],
} and my (simplified) babel config is: module.exports = function () {
const envOptions = {
loose: true,
modules: false,
shippedProposals: true,
useBuiltIns: 'usage',
corejs: 2
}
const presets = [
['@babel/preset-env', envOptions],
]
const plugins = [
['@babel/plugin-transform-runtime', { useESModules: true }]
]
return {
presets,
plugins,
}
} This ends up with these imports in the import _extends from '@babel/runtime/helpers/esm/extends';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import 'regenerator-runtime/runtime';
import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator'; and these require statements in the var _extends = _interopDefault(require('@babel/runtime/helpers/esm/extends'));
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
require('regenerator-runtime/runtime');
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/esm/asyncToGenerator')); The require for The var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator'));
require('regenerator-runtime/runtime');
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); However, the non-esm files are also referenced from the import _extends from '@babel/runtime/helpers/extends';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import 'regenerator-runtime/runtime';
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; So what I would really like is some way to flip that option based on the output format of rollup, but from reading the documentation and the |
You should split rollup config into two (you can export array of configs). And pass |
Thank you @TrySound. The config in question is actually being used as a babel preset itself (there's a reason I said "simplified" in my description), so I made |
Any consistent solution on this? |
Hi guys, getting kind of related error using Next.js...
here is my sandbox: Any view/update on how to fix this? I am kind of stuck for days... Much appreciated! |
The proper solution for this is to only set However, starting from Babel 7.13.0 it will be possible to always omit |
Bug Report
@babel/runtime:
Current Behavior
Input Code
babelrc
Expected behavior/code
Expect no error
The text was updated successfully, but these errors were encountered: