Michael Lindell
Michael Lindell

Reputation: 21

TypeError: (0 , _index.default) is not a function when using Babel as a library in a Rollup bundle

I am trying to include Babel and rollup.js in an application bundle (which itself is bundled using Rollup) that is to be run in the browser (for transpiling and bundling inside the browser). I have rollup working without @rollup/plugin-babel enabled. As soon as I import @rollup/plugin-babel (and thereby Babel) in the application code, I get this error after calling rollup():

babelv.min.js:101604 Uncaught (in promise) TypeError: (0 , _index.default) is not a function
at NodePath.traverse (babelv.min.js:101604)
at Scope.crawl (babelv.min.js:68561)
at Scope.init (babelv.min.js:68505)
at NodePath.setScope (babelv.min.js:100024)
at NodePath.setContext (babelv.min.js:100040)
at new File (babelv.min.js:106640)
at normalizeFile$ (babelv.min.js:120308)
at tryCatch (babelv.min.js:10464)
at Generator.invoke [as _invoke] (babelv.min.js:10681)
at Generator.next (babelv.min.js:10517)

I am using this Babel configuration:

"presets": [
    ["@babel/preset-env", {
        "useBuiltIns": "entry",
        "corejs": 3
    }]
]

I have the core-js/regenerator-runtime stuff figured out and working properly.

Looking at the Babel source inside the package (@babel/traverse/lib/path/index.js), the (0, ... syntax is present, so it isn't being mangled by Babel:

traverse(visitor, state) {
     (0, _index.default)(this.node, visitor, this.scope, state, this);
}

I've looked at other questions with similar errors that ended up being caused by incorrect named/default imports and circular dependencies, but neither appear to be the case here. I'm wondering if it's possibly a bug. Or, maybe more likely, I need some special plugins or configuration to properly bundle Babel.

Upvotes: 1

Views: 1239

Answers (1)

Michael Lindell
Michael Lindell

Reputation: 21

Ended up using Webpack. Works great.

Upvotes: 1

Related Questions