我一直遵循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"
}
}
当我在终端中尝试以下行时,它说找不到软件包:
npm install --save-dev @babel/plugin-transform-class-properties
如何克服此错误消息?
答案 0 :(得分:2)
由于您使用的是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”。
这是intentionally done by Babel,目的是使人们更加了解TC39流程中的功能。
如果您实际上仍在使用Babel 6(很难说,因为您的package.json
中有Babel 7和Babel 6条目,那么您需要@Morty的注释。