繁体   English   中英

如何安装节点模块@babel/plugin-transform-class-properties?

[英]How do I install node module @babel/plugin-transform-class-properties?

我一直在按照https://github.com/babel/babelify的说明进行操作,但在此过程中遇到了错误。 我运行以下代码行:

browserify script.js -o bundle.js -t [ babelify --presets [ @babel/preset-env @babel/preset-react ] --plugins [ @babel/plugin-transform-class-properties ] ]

终端产生以下错误消息:

Error: Cannot find module '@babel/plugin-transform-class-properties' from '/path/to/file' while parsing file: /path/to/file/circle-graph-2.js

我的 package.json 文件是

{
  "name": "robert",
  "version": "1.0.0",
  "description": "This is the third step of my first attempt to learn canvas. I want to improve a piece a made a few weeks ago about the division of [occupations](http://nbremer.github.io/occupations/). The D3.js version has so many DOM elements due to all the small bar charts that it is very slow. Therefore, I hope that a canvas version might improve things",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "babel": {
    "presets": [
      "es2015",
      "react",
      "transform-class-properties"
    ]
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.1.6",
    "babel-core": "^6.26.3",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babelify": "^10.0.0"
  }
}

当我在终端中尝试以下行时,它说找不到 package:

npm install --save-dev @babel/plugin-transform-class-properties

如何克服此错误消息?

由于您使用的是Babel 7(基于您的"@babel/core": "^7.1.6"条目),我认为您正在寻找npm install --save-dev @babel/plugin-proposal-class-properties是Babel 7插件的新版本。请注意,名称从“plugin-transform-class-properties” - >“babel-plugin-proposal-class-properties”更改。

这是Babel故意做的 ,让人们更加了解TC39流程中的功能。

如果你实际上仍然在使用Babel 6(很难说你的package.json有Babel 7和Babel 6条目,那么@Morty的评论就是你所需要的。

我的项目有同样的错误,但是npm install --save-dev @babel/plugin-proposal-class-properties install对我来说还不够。

node-sass for babel 7.11.4搜索node-sass for babel 7.11.4这里找到了修复

我的版本基本上是错误的,所以我在package.json文件中添加了"@babel/core": "^7.13.14"并再次运行npm install

如果您使用的是最新版本。 只需运行npx babel-upgrade ,它将显示您需要在 babel.rc 文件中更新的更改

暂无
暂无

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

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