실험적 구문 'classProperties'에 대한 지원이 현재 활성화되어 있지 않습니다.
Django 프로젝트에서 React를 설정하는 동안이 오류가 발생했습니다.
모듈 빌드의 ModuleBuildError 실패 (./node_modules/babel-loader/lib/index.js에서) : SyntaxError : C : \ Users \ 1Sun \ Cebula3 \ cebula_react \ assets \ js \ index.js : 실험적 구문 'classProperties 지원 '는 현재 활성화되어 있지 않습니다 (17 : 9) :
15 |
16 | class BodyPartWrapper extends Component {
> 17 | state = {
| ^
18 |
19 | }
20 |
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the
'plugins' section of your Babel config to enable transformation.
그래서 @ babel / plugin-proposal-class-properties를 설치하고 이것을 babelrc에 넣었습니다.
package.json
{
"name": "cebula_react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config prod.config.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"react-hot-loader": "^4.3.6",
"webpack": "^4.17.2",
"webpack-bundle-tracker": "^0.3.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"dependencies": {
"react": "^16.5.0",
"react-dom": "^16.5.0"
}
}
바벨 르크
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
그러나 오류는 여전히 존재합니다. 무엇이 문제입니까 ??
변화
"plugins": [
"@babel/plugin-proposal-class-properties"
]
에
"plugins": [
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
이것은 나를 위해 일했습니다.
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-proposal-class-properties"
]
]
}
.babelrc 파일을 위의 코드로 바꿉니다. 그것은 나를 위해 문제를 해결했습니다.
웹팩 프로젝트 솔루션
@babel/plugin-proposal-class-properties
webpack config 플러그인 에 추가하여이 문제를 해결했습니다 . 내 모듈 섹션은 webpack.config.js
다음과 같습니다.
module: {
rules: [
{
test: path.join(__dirname, '.'),
exclude: /(node_modules)/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env',
'@babel/react',{
'plugins': ['@babel/plugin-proposal-class-properties']}]
}
}
]
}
먼저 @ babel / plugin-proposal-class-properties 를 dev 종속성으로 설치하십시오.
npm install @babel/plugin-proposal-class-properties --save-dev
그런 다음 .babelrc를 다음과 같이 수정하십시오.
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
[
"@babel/plugin-proposal-class-properties"
]
]
}
package.json 이 있는 루트 디렉토리에있는 .babelrc 파일 .
변경 사항을 적용하려면 웹팩 개발 서버를 다시 시작해야합니다.
plugin-proposal-class-properties 설치
npm install @babel/plugin-proposal-class-properties --save-dev
다음을 추가하여 webpack.config.js를 업데이트하십시오.
'plugins': ['@babel/plugin-proposal-class-properties']}]
거의 3 시간 동안 동일한 오류를 검색하고 시간을 보낸 후 React에 이름 가져 오기를 사용하고 있음을 발견했습니다.
import { React } from 'react';
그것은 완전히 잘못된 것입니다. 다음으로 전환하면됩니다.
import React from 'react';
모든 오류가 사라졌습니다. 누군가에게 도움이되기를 바랍니다. 이것은 내 .babelrc입니다.
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
webpack.config.js
const path = require('path');
const devMode = process.env.Node_ENV !== 'production';
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
entry: './src/App.js',
devtool: 'source-map',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'App.js'
},
mode: 'development',
devServer: {
contentBase: path.resolve(__dirname, 'public'),
port:9090,
open: 'google chrome',
historyApiFallback: true
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},{
test: /\.(sa|sc|c)ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[local]--[hash:base64:5]',
sourceMap: true
}
},{
loader: 'sass-loader'
}
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: devMode ? '[name].css' : '[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css'
})
]
}
package.json
{
"name": "expense-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"serve": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"css-loader": "^1.0.0",
"mini-css-extract-plugin": "^0.4.3",
"node-sass": "^4.9.3",
"react-router-dom": "^4.3.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9"
},
"dependencies": {
"normalize.css": "^8.0.0",
"react": "^16.5.2",
"react-dom": "^16.5.2"
}
}
내 .babelrc
무시 된 문제를 찾았 지만 babel.config.js
다음을 만들고 추가합니다.
module.exports = {
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-regenerator',
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true,
},
],
],
presets: [
"@babel/preset-flow",
'module:metro-react-native-babel-preset',
],
};
And it works for me on React Native application, I think this also would help React apps as well.
I am using the babel parser explicitly. None of the above solutions worked for me. This worked.
const ast = parser.parse(inputCode, {
sourceType: 'module',
plugins: [
'jsx',
'classProperties', // '@babel/plugin-proposal-class-properties',
],
});
I'm using yarn. I had to do the following to overcome the error.
yarn add @babel/plugin-proposal-class-properties --dev
I just tested on Laravel Framework 5.7.19 and the following steps work:
Make sure your .babelrc file is in the root folder of your application, and add the following code:
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
Run npm install --save-dev @babel/plugin-proposal-class-properties
.
Run npm run watch
.
'IT TIP' 카테고리의 다른 글
Magento의 getChildHtml 이해 (0) | 2020.12.06 |
---|---|
Jekyll / Liquid에서 문자열을 다른 문자열에 연결 / 추가하는 방법은 무엇입니까? (0) | 2020.12.06 |
.NET의`Array.Sort ()`메서드에서 사용하는 정렬 알고리즘이 안정적인 알고리즘입니까? (0) | 2020.12.06 |
Datagridview에서 행을 선택하려면 마우스 오른쪽 버튼을 클릭하고 삭제할 메뉴를 표시합니다. (0) | 2020.12.06 |
! = 및! ==와 같지 않은 PHP (0) | 2020.12.06 |