简体   繁体   English

@ babel / plugin-proposal-class-properties不起作用

[英]@babel/plugin-proposal-class-properties doesn't work

I have such a project structure: 我有这样一个项目结构:

/main-folder

  /apps
    /app — // I want to import "project-b" here
      /node_modules
      /public
      /src
        |app.js
        |app.css
      |.babelrc
      |package.json
      |package-lock.json
      |webpack.config.js

  /static
    /project-b — // Project that I want to export
      /node_modules
      /public
      /src
        /lib
          ...components
      |.babelrc
      |package.json
      |package-lock.json

Everything okay when I try to import components without class properties. 当我尝试导入没有类属性的组件时,一切都还可以。 But if I import component with class properties: 但是,如果我导入具有类属性的组件:

在此输入图像描述

I thought if I add .babelrc it'll work (I added .babelrc to the app and project-b folders and it still doesn't work) 我想如果我添加.babelrc它会工作(我将.babelrc添加到appproject-b文件夹,它仍然无效)

.babelrc:

{
  "presets": ["@babel/preset-react","@babel/preset-env"],
  "plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}

app package.json:

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "webpack": "webpack",
    "start:dev": "webpack-dev-server",
    "webpack:production": "webpack -p"
  },
  "author": "namename",
  "license": "MIT",
  "dependencies": {
    "css-loader": "^1.0.1",
    "entrl-ui-kit": "^1.0.3",
    "file-loader": "^2.0.0",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-router-dom": "^4.3.1",
    "react-transition-group": "^2.5.0",
    "style-loader": "^0.23.1"
  },
  "devDependencies": {
    "@babel/core": "^7.1.6",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/preset-env": "^7.1.6",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.4",
    "webpack": "^4.26.0",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.10"
  }
}

project-b package.json:

 {
  "name": "project-b",
  "version": "1.0.0",
  "author": "namename",
  "license": "MIT",
  "main": "dist/index.js",
  "module": "dist/index.js",
  "files": [
    "dist"
  ],
  "scripts": {
    "start": "react-scripts start",
    "build-examples": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "build": "rimraf ./build && mkdirp ./build && babel -d ./build ./src"
  },
  "devDependencies": {
    "@babel/cli": "^7.1.5",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.0-beta.6",
    "babel-preset-latest": "^6.24.1",
    "mkdirp": "^0.5.1",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-scripts": "^2.1.1",
    "react-transition-group": "^2.5.0",
    "rimraf": "^2.6.2"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "dependencies": {
    "babel-core": "^7.0.0-bridge.0"
  }
}  

All I need to do is add babel.config.js to the root folder: 我需要做的就是将babel.config.js添加到根文件夹:

Thanks to loganfsmyth ! 感谢loganfsmyth

/main-folder
  |babel.config.js — //HERE!
  /apps
    /app — // I want to import "project-b" here
      /node_modules
      /public
      /src
        |app.js
        |app.css
      |.babelrc
      |package.json
      |package-lock.json
      |webpack.config.js

  /static
    /project-b — // Project that I want to export
      /node_modules
      /public
      /src
        /lib
          ...components
      |.babelrc
      |package.json
      |package-lock.json

babel.config.js:

module.exports = {
  babelrcRoots: [
    ".",
    "static/project-b/*"
  ]
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到模块“@babel/plugin-proposal-class-properties” - Error: Cannot find module '@babel/plugin-proposal-class-properties' 带有 Babel 的 ESLint:在 .eslintrc 中未找到声明的 plugin-proposal-class-properties - ESLint with Babel: plugin-proposal-class-properties not found declared in .eslintrc 当前未启用对实验语法“classProperties”的支持 (8:16)。 添加@babel/plugin-proposal-class-properties - Support for the experimental syntax 'classProperties' isn't currently enabled (8:16). Add @babel/plugin-proposal-class-properties @babel/plugin-proposal-class-properties 仍然失败,“classProperties 当前未启用” - @babel/plugin-proposal-class-properties Still Fails with "classProperties isn't currently enabled" 无法解决找不到插件“proposal-class-properties” - Unable to resolve Could not find plugin “proposal-class-properties” Babel插件 - 提议装饰器未按预期工作 - Babel plugin-proposal-decorators not working as expected 如何让 @babel/plugin-proposal-private-methods 在 vue.js webpack 模板中工作? - How to make @babel/plugin-proposal-private-methods work in the vue.js webpack template? 带有第 2 阶段提案和 Babel 7 的类装饰器 - Class decorator with stage-2 proposal and Babel 7 无法让 browserify 使用 babel-plugin-transform-class-properties - Can't get browserify to use babel-plugin-transform-class-properties 使用 Firebase 在 CodeSandbox 上找不到/安装 babel 插件“proposal-decorators” - Could not find/install babel plugin 'proposal-decorators' on CodeSandbox with Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM