简体   繁体   English

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

[英]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.

相关问题 如何使用 babel 插件将 commonjs 转换为 es2015 模块? - How can I transform commonjs to es2015 module with babel plugin? 错误:找不到模块“@babel/plugin-proposal-class-properties” - Error: Cannot find module '@babel/plugin-proposal-class-properties' 如何在Babel + transform-decorators-legacy中禁用定义类的属性 - How to disable defining class properties in Babel + transform-decorators-legacy Nuxt 2.x:添加 babel 的转换插件,适用于导入的 node_module 文件 - Nuxt 2.x: Add babel's transform plugin, that work on imported node_module file 无法让 browserify 使用 babel-plugin-transform-class-properties - Can't get browserify to use babel-plugin-transform-class-properties 使用 Babel,我如何*不*编译掉类属性,因为浏览器现在原生支持它们? - With Babel, how do I *not* compile away class properties, since browsers support them natively now? 没有再生器的babel-plugin-transform-async-to-module-method - babel-plugin-transform-async-to-module-method without regenerator Babel 插件 - 如何在不做出反应的情况下转换 JSX - Babel plugin - How to transform JSX without react 重要的 npm install @babel/plugin-transform-react-jsx 不起作用 - Important npm install @babel/plugin-transform-react-jsx is not working 找不到模块'babel-plugin-transform-decorators-legacy' - Cannot find module 'babel-plugin-transform-decorators-legacy'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM