Reputation: 5432
Here is some functionality that used to work for me with Babel 6, but I'm having issues with Babel 7. I'm trying to export a (default) class as a library. Currently I get the following error when I try to import it.
Uncaught SyntaxError: The requested module './dist/datastore.js' does not provide an export named 'default'
My configurations are nearly identical to my former configs, just updated with Babel 7.
Bits from Webpack:
output: {
path: `${__dirname}/dist`,
filename: `${moduleName}.js`,
library: 'datastore',
libraryExport: 'default',
libraryTarget: 'umd',
umdNamedDefine: true
},
Bits from my entrypoint:
import DataStore from './datastore';
export default DataStore;
Bits from .babelrc:
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": "current"
},
"modules": false
}]
],
"plugins": [
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-transform-destructuring",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
]
}
Anyone have any ideas?
Upvotes: 3
Views: 6331
Reputation: 59
If you are using babel 7 you need to load this package:
npm i --save-dev babel-plugin-add-module-exports
And then add in your babel configuration this plugin 'add-module-exports':
module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
browsers: ['last 2 versions', 'safari >= 7']
}
}
]
],
plugins: ['add-module-exports']
};
Upvotes: 5