如何安装node-module@babel/plugin-transform类属性



我一直在遵循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

如何克服此错误消息?

由于您使用的是Babel7(基于您的"@babel/core": "^7.1.6"条目(,我认为您正在寻找npm install --save-dev @babel/plugin-proposal-class-properties,这是Babel7。请注意,名称从"插件转换类属性"->"babel-plugin-provision类属性"更改。

这是Babel有意做的,目的是让人们更加了解TC39过程中的功能所在。

如果你真的还在使用Babel 6(很难说,因为你的package.json中有一个Babel 7和Babel 6条目,@Morty的评论就是你需要的。

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

搜索node-sass for babel 7.11.4在此处找到修复

我基本上使用了错误的版本,所以我将"@babel/core": "^7.13.14"添加到package.json文件中,然后再次运行npm install

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

相关内容

最新更新