如何解决无法配置@babel/core: .inherits must be a function, or undefined
我无法构建我的项目,不断收到 babel 错误:
ERROR in ./src/index.js
Module build Failed (from ./node_modules/babel-loader/lib/index.js):
Error: [BABEL] C:\my-project\src\index.js: .inherits must be a function,or undefined
at assertFunction (C:\my-project\node_modules\@babel\core\lib\config\validation\option-assertions.js:140:11)
at C:\my-project\node_modules\@babel\core\lib\config\validation\plugins.js:63:7
at Array.forEach (<anonymous>)
at validatePluginobject (C:\my-project\node_modules\@babel\core\lib\config\validation\plugins.js:54:20)
at C:\my-project\node_modules\@babel\core\lib\config\full.js:261:55
at Generator.next (<anonymous>)
at Function.<anonymous> (C:\my-project\node_modules\@babel\core\lib\gensync-utils\async.js:16:3)
at Generator.next (<anonymous>)
at step (C:\my-project\node_modules\gensync\index.js:261:32)
at evaluateAsync (C:\my-project\node_modules\gensync\index.js:291:5)
at Function.errback (C:\my-project\node_modules\gensync\index.js:113:7)
at errback (C:\my-project\node_modules\@babel\core\lib\gensync-utils\async.js:60:18)
at async (C:\my-project\node_modules\gensync\index.js:188:31)
at onFirstPause (C:\my-project\node_modules\gensync\index.js:216:13)
at Generator.next (<anonymous>)
at cachedFunction (C:\my-project\node_modules\@babel\core\lib\config\caching.js:58:46)
at cachedFunction.next (<anonymous>)
at loadpluginDescriptor (C:\my-project\node_modules\@babel\core\lib\config\full.js:252:17)
at loadpluginDescriptor.next (<anonymous>)
at loadpluginDescriptors (C:\my-project\node_modules\@babel\core\lib\config\full.js:159:30)
at loadpluginDescriptors.next (<anonymous>)
at C:\my-project\node_modules\@babel\core\lib\config\full.js:187:21
at Generator.next (<anonymous>)
at loadFullConfig (C:\my-project\node_modules\@babel\core\lib\config\full.js:170:5)
at loadFullConfig.next (<anonymous>)
at Function.transform (C:\my-project\node_modules\@babel\core\lib\transform.js:17:45)
at transform.next (<anonymous>)
at step (C:\my-project\node_modules\gensync\index.js:269:25)
at C:\my-project\node_modules\gensync\index.js:273:13
at async.call.result.err.err (C:\my-project\node_modules\gensync\index.js:223:11)
@ multi ./src/main.less ./src/index.js my-project[1]
我使用的是 webpack 4.46.*
这是我的依赖项:
"@babel/cli": "7.13.10","@babel/core": "7.13.10","@babel/eslint-parser": "^7.13.10","@babel/plugin-proposal-class-properties": "7.13.0","@babel/plugin-proposal-decorators": "^7.13.5","@babel/plugin-proposal-object-rest-spread": "7.13.8","@babel/plugin-Syntax-class-properties": "^7.12.13","@babel/plugin-transform-runtime": "^7.13.10","@babel/preset-env": "7.13.10","@babel/preset-react": "7.12.13","@babel/runtime-corejs2": "^7.13.10",
问题来了: ** 错误:[BABEL] C:\my-project\src\index.js: .inherits must be a function,or undefined**
我尝试了不同版本的@babel 插件,没有任何帮助。
这是我的 .babelrc:
{
"presets": [
"@babel/preset-env","@babel/preset-react"
],"plugins": [
[ "@babel/plugin-proposal-decorators",{ "legacy": true } ],["@babel/plugin-transform-runtime",{ "corejs": 2} ],"@babel/plugin-proposal-class-properties","@babel/plugin-proposal-object-rest-spread"
]
}
很遗憾,我无法分享我的 webpack 配置。
class X {
static propTypes = 10
}
所以我认为它可能是 @babel/plugin-proposal-class-properties
。
请帮忙!
更新
所以,它适用于下一个配置:
{
"presets": [
"@babel/preset-react"
],"plugins": [
[ "@babel/plugin-proposal-decorators","@babel/plugin-Syntax-class-properties",]
}
import sinon from 'sinon';
^^^^^^
SyntaxError: Cannot use import statement outside a module
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。