首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >babel-loader错误- TypeError: val不是函数

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

Stack Overflow用户
提问于 2019-02-27 06:01:23
回答 2查看 580关注 0票数 4

我正在尝试使用webpack和巴别塔,但我收到的错误似乎不是在线上的任何地方。这是非常简单的js,当我测试的时候,它仍然在不应该出现的地方给我错误。

代码语言:javascript
复制
var test = () => {
  console.log("Test")
}
test()

我得到了一个错误:

代码语言:javascript
复制
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

代码语言:javascript
复制
"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"
  }

几个小时以来,我一直在尝试解决这个问题,但都无济于事,在谷歌上找不到它,我简直要疯了。

EN

回答 2

Stack Overflow用户

发布于 2019-02-27 21:38:21

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

票数 0
EN

Stack Overflow用户

发布于 2019-07-27 12:21:13

如果您使用的是babel.config.js而不是.babelrc,并且您拥有以下内容:

代码语言:javascript
复制
module.exports = api => {
  api.cache();

  return {
    ...
  }
}

cache需要布尔型参数。因此可以像这样将truefalse传递到cache()中:api.cache(true);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54894849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档