This error occured after upgrading babel to babel7, and change the preset-env to "modules": "commonjs"
import(`antd/lib/locale/${lang}`).then(module => {
this.setState({ locale: module.default });
});
{
"presets": [
"@babel/preset-react",
[
"@babel/preset-env",
{
"modules": "commonjs"
}
]
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": true
}
],
[
"@babel/plugin-transform-runtime",
{
"corejs": 2,
"helpers": false,
"regenerator": true
}
],
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
false
],
[
"@babel/plugin-syntax-dynamic-import",
false
],
[
"@babel/plugin-proposal-optional-chaining",
false
],
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-json-strings",
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
[
"@babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-do-expressions",
"@babel/plugin-proposal-function-bind"
]
}
And if I change back to "modules": false, I got another error here:
For the error2, I found the glob is undefined here in glob.Raphael
.
I wonder how to solve these errors, thanks.
CodePudding user response:
I find the answer here:
solved it by adding plugins: ["@babel/plugin-transform-modules-commonjs"]
https://github.com/webpack-contrib/imports-loader/issues/68#issuecomment-528788909