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

Ver*_*rry 5 javascript babel node.js

我一直在按照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 ] ]
Run Code Online (Sandbox Code Playgroud)

终端产生以下错误信息:

Error: Cannot find module '@babel/plugin-transform-class-properties' from '/path/to/file' while parsing file: /path/to/file/circle-graph-2.js
Run Code Online (Sandbox Code Playgroud)

我的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"
  }
}
Run Code Online (Sandbox Code Playgroud)

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

npm install --save-dev @babel/plugin-transform-class-properties
Run Code Online (Sandbox Code Playgroud)

如何克服此错误消息?

Mat*_*bst 7

由于您使用的是Babel 7(根据您的"@babel/core": "^7.1.6"输入),我认为您正在寻找npm install --save-dev @babel/plugin-proposal-class-properties哪个是Babel 7的新版本插件。请注意名称从“ plugin-transform-class-properties”->“ babel-插件提案类属性”。

这是故意做通天使人们更清楚地意识到其中的特点是在TC39过程。

如果您实际上仍然在使用Babel 6(很难说,因为您的条目中有Babel 7和Babel 6条目,package.json@Morty的注释就是您所需要的。