打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
javascript – 语法错误 – 目前尚未启用对实验语法’decorators-legacy’的支持

我正在尝试用装饰器构建JS反应项目.我的.babelrc看起来像这样:

{  "presets": [    "@babel/preset-env",    "@babel/preset-react",  ],  "plugins": [    "@babel/plugin-transform-runtime",    "@babel/plugin-transform-object-assign",    [      "@babel/plugin-proposal-decorators",      {        "legacy": true      }    ],    ["@babel/plugin-proposal-class-properties", { "loose": true }]  ]}

添加@ babel / plugin-proposal-decorators问题再次出现.

我正在使用babel 7,webpack 4并做出反应16.5

webpack.config.js:

const path = require("path");const webpack = require("webpack");const componentName = "reports-desktop";const publicFolderRelativePath = "../../../../../../public/js";const ignorePlugin = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);module.exports = {    entry: './reports-desktop.js'    ,    output: {        path: path.resolve(__dirname, publicFolderRelativePath),        filename: `${componentName}.js`    },    module: {        rules: [            {                test: /\.js$/,                exclude: /node_modules/,                use: {                    loader: "babel-loader"                }            }        ]    },    plugins: [        ignorePlugin    ]};

的package.json:

{  "name": "captain",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {    "watch": "webpack -w --mode development --progress --color --display-error-details",    "build": "webpack --mode production"  },  "keywords": [],  "author": "",  "license": "ISC",  "devDependencies": {    "@babel/core": "^7.0.0",    "@babel/plugin-proposal-class-properties": "^7.0.0",    "@babel/plugin-proposal-decorators": "^7.0.0",    "@babel/plugin-transform-object-assign": "^7.0.0",    "@babel/plugin-transform-runtime": "^7.0.0",    "@babel/preset-env": "^7.0.0",    "@babel/preset-react": "^7.0.0",    "@babel/preset-stage-1": "^7.0.0",    "@babel/preset-stage-2": "^7.0.0",    "babel-loader": "^8.0.2",    "babel-plugin-transform-decorators": "^6.24.1",    "react": "^16.5.0",    "react-dom": "^16.5.0",    "react-redux": "^5.0.7",    "react-router-dom": "^4.3.1",    "redux": "^4.0.0",    "webpack": "^4.17.3",    "webpack-cli": "^3.1.0"  },  "dependencies": {    "axios": "^0.18.0",    "dropzone": "^5.5.1",    "lodash": "^4.17.10",    "moment": "^2.22.2",    "prop-types": "^15.6.2",    "react-addons-update": "^15.6.2",    "react-bootstrap": "^0.32.4",    "react-datetime": "^2.15.0",    "react-dnd": "^5.0.0",    "react-dnd-html5-backend": "^5.0.1",    "react-media": "^1.8.0",    "react-tooltip": "^3.8.1"  }}

我可能使用@ babel / plugin-proposal-decorators错了吗?正如它在文档中所说,这应该解决我的问题,但它仍然出现.

解决方法:

我遇到了同样的问题,但我能够通过运行npm install –save-dev @ babel / plugin-proposal-decorators并添加[“@ babel / plugin-proposal-decorators”,{“legacy”: true}]到我的.babelrc中的插件部分.

对我来说.babelrc的插件部分现在看起来像这样:

"plugins": [  ["@babel/plugin-proposal-decorators", { "legacy": true }]]
来源:https://www.icode9.com/content-1-485501.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
你必须要知道的babel二三事
入门babel,我们需要了解些什么
详解babel8.X版本用法填坑
Vue中关于Babel的作用和用法解释
babel 版本原因运行报错,解决办法
webpack.config.js和package.json
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服