【发布时间】:2019-07-20 13:08:58
【问题描述】:
我正在尝试使用 webpack 和 babel,但我遇到的错误似乎在线上任何地方都没有。在我测试时它现在是非常简单的 js,但它仍然在不应该出现的地方给我错误。
var test = () => {
console.log("Test")
}
test()
我收到了错误:
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,所以我看不出哪里出错了。这是我的 project.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内容,我可以告诉你哪里出了问题。 -
我刚刚查看了一下,发现括号中的
app.cache()没有任何值。我将它设置为true,它现在可以工作了。
标签: javascript reactjs webpack ecmascript-6 babeljs