[英]How do I install node module @babel/plugin-transform-class-properties?
I have been following instructions from https://github.com/babel/babelify and I ran into an error along the way.我一直在按照https://github.com/babel/babelify的说明进行操作,但在此过程中遇到了错误。 I run the following line of code:我运行以下代码行:
browserify script.js -o bundle.js -t [ babelify --presets [ @babel/preset-env @babel/preset-react ] --plugins [ @babel/plugin-transform-class-properties ] ]
The terminal produces the following error message:终端产生以下错误消息:
Error: Cannot find module '@babel/plugin-transform-class-properties' from '/path/to/file' while parsing file: /path/to/file/circle-graph-2.js
My package.json file is我的 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"
}
}
When I try the following line in the terminal then it says the package isn't found:当我在终端中尝试以下行时,它说找不到 package:
npm install --save-dev @babel/plugin-transform-class-properties
How do I overcome this error message?如何克服此错误消息?
Since you are on Babel 7 (based on your "@babel/core": "^7.1.6"
entry), I think you are looking for npm install --save-dev @babel/plugin-proposal-class-properties
which is the new version of the plugin for Babel 7. Notice the name change from "plugin-transform-class-properties" -> "babel-plugin-proposal-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”更改。
This was intentionally done by Babel to make people more aware of where features are in the TC39 process. 这是Babel故意做的 ,让人们更加了解TC39流程中的功能。
If you are actually still on Babel 6 (hard to tell since you have a Babel 7 and Babel 6 entry in your package.json
, the comment by @Morty is what you need. 如果你实际上仍然在使用Babel 6(很难说你的package.json
有Babel 7和Babel 6条目,那么@Morty的评论就是你所需要的。
Had the same error for my project, but the npm install --save-dev @babel/plugin-proposal-class-properties
install was not enough for me.我的项目有同样的错误,但是npm install --save-dev @babel/plugin-proposal-class-properties
install对我来说还不够。
Searched for node-sass for babel 7.11.4
Found the fix here node-sass for babel 7.11.4
搜索node-sass for babel 7.11.4
在这里找到了修复
I was basically in the wrong version so I added "@babel/core": "^7.13.14"
to my package.json
file and ran npm install
again.我的版本基本上是错误的,所以我在package.json
文件中添加了"@babel/core": "^7.13.14"
并再次运行npm install
。
if you're using that latest version.如果您使用的是最新版本。 Just run npx babel-upgrade
and it will display changes you need to update in your babel.rc file只需运行npx babel-upgrade
,它将显示您需要在 babel.rc 文件中更新的更改
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.