繁体   English   中英

babel-loader错误 - TypeError:val不是函数

[英]babel-loader error - TypeError: val is not a function

我正在尝试使用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"
  }

我一直试图弄清楚这几个小时无济于事,我疯了却无法在谷歌上找到它。

babel.config.js ,我将app.cache()的参数设置为true ,现在可以正常工作了。

如果你使用babel.config.js而不是.babelrc而且你有这个:

module.exports = api => {
  api.cache();

  return {
    ...
  }
}

cache需要一个布尔参数。 所以要么将truefalse传递给cache()就像这样: api.cache(true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM