错误:.plugins[3] 只能是二元组或三元组

Posted

技术标签:

【中文标题】错误:.plugins[3] 只能是二元组或三元组【英文标题】:Error: .plugins[3] may only be a two-tuple or three-tuple 【发布时间】:2021-01-30 05:34:29 【问题描述】:

我正在尝试让storybookJs 工作,当我运行命令npm run storybook 时出现此错误:

Error: .plugins[3] may only be a two-tuple or three-tuple

这是我的文件 .babelrc


  "presets": ["react", "es2015-node5"],
  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    "transform-class-properties",
    [
      "module-alias",
        
          "src": "./src/screens",
          "expose": "screens"
        ,
        
          "src": "./config",
          "expose": "config"
        ,
        
          "src": "./src/shared",
          "expose": "shared"
        ,
        
          "src": "./package.json",
          "expose": "package"
        
    ]
  ]

babel 包版本

"@babel/core": "^7.12.0", "babel": "^6.23.0", "babel-cli": "^6.26.0", "babel-eslint": "^8.2.3", "babel-loader": "^7.1.4", "babel-plugin-module-alias": "^1.6.0", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-es2015-node5": "^1.2.0", “babel-preset-react”:“^6.24.1”

【问题讨论】:

【参考方案1】:

您缺少一组[],例如,请参阅the docs for the plugin。

[
  "module-alias",
    
      "src": "./src/screens",
      "expose": "screens"
    ,
    
      "src": "./config",
      "expose": "config"
    ,
    
      "src": "./src/shared",
      "expose": "shared"
    ,
    
      "src": "./package.json",
      "expose": "package"
    
]

应该是

[
  "module-alias", [
    
      "src": "./src/screens",
      "expose": "screens"
    ,
    
      "src": "./config",
      "expose": "config"
    ,
    
      "src": "./src/shared",
      "expose": "shared"
    ,
    
      "src": "./package.json",
      "expose": "package"
    
  ]
]

【讨论】:

我把它们拿出来是因为我有这个错误Error: .plugins[3][1] must be an object, false, or undefined 那么整个配置都是错误的,因为你的配置是针对 Babel 6.x 而你使用的是 Babel 7.x "@babel/core": "^7.12.0", "@ckeditor/ckeditor5-dev-utils": "^12.0.1", "@ckeditor/ckeditor5-theme-lark": "^18.0.0", "babel": "^6.23.0", "babel-cli": "^6.26.0", "babel-eslint": "^8.2.3", "babel-loader": "^7.1.4", "babel-plugin-module-alias": "^1.6.0", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-es2015-node5": "^1.2.0", "babel-preset-react": "^6.24.1" @babel/core 是 7.x,babel 是 6.x

以上是关于错误:.plugins[3] 只能是二元组或三元组的主要内容,如果未能解决你的问题,请参考以下文章

如何使用整洁的文本使用二元组和三元组

如何找到字符二元组和三元组?

如何实现潜在狄利克雷分配以在主题中给出二元组/三元组而不是一元组

怎么根据三元相图画出二元相图

《程序员代码面试指南》第八章 数组和矩阵问题 不重复打印排序数组中相加和为给定值的所有二元组和三元组

「 solution set」 AGC037