我正在尝试使用webpack和babel,但是出现了一些错误,这些错误似乎在网上找不到解决方法。目前这只是一段非常简单的js代码,但仍然在不应该出错的地方报错。
var test = () => {
console.log("Test")
}
test()
I'm getting the error:
ERROR in ./dist/main.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: val is not a function
ERROR in ./dist/main.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: val is not a function
at cache.using (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\caching.js:179:47)
at CacheConfigurator.using (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\caching.js:132:17)
at Object.cacheFn [as cache] (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\caching.js:179:18)
at module.exports (C:\Users\Bacon\Desktop\ReactProj\jsx\babel.config.js:2:9)
at readConfigJS (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\files\configuration.js:212:15)
at cachedFunction (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\caching.js:33:19)
at readConfig (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\files\configuration.js:173:56) at findRootConfig (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\files\configuration.js:148:16)
at buildRootChain (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\config-chain.js:78:44)
at loadPrivatePartialConfig (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\partial.js:85:55)
at Object.loadPartialConfig (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\@babel\core\lib\config\partial.js:110:18)
at Object.<anonymous> (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:140:26)
at Generator.next (<anonymous>)
at asyncGeneratorStep (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:3:103)
at _next (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:5:194)
at C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:5:364
at new Promise (<anonymous>)
at Object.<anonymous> (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:5:97)
at Object._loader (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:220:18)
at Object.loader (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:56:18)
at Object.<anonymous> (C:\Users\Bacon\Desktop\ReactProj\jsx\node_modules\babel-loader\lib\index.js:51:12)
我的代码中没有任何 val,所以我不知道出了什么问题。这是我的项目.json中的 devDependencies:
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/preset-es2015": "^7.0.0-beta.53",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.5",
"standard": "^12.0.1",
"webpack": "^4.29.5",
"webpack-cli": "^3.2.3"
}
我已经试图解决这个问题几个小时了,却一无所获。我疯了,因为在谷歌上找不到答案。
jsx\babel.config.js
,它调用了一个函数,然后抛出异常,因此很可能您的配置以不正确的方式调用了一个函数。如果您包含babel.config.js
的内容,我可以告诉您出了什么问题。 - loganfsmythapp.cache()
括号里没有任何值。我将其设置为true
,现在它可以正常工作了。 - Josh Bacon