相关疑难解决方法(0)

当前未启用对实验性语法“jsx”的支持

我正在尝试运行非常简单的代码,但出现错误,我没有使用 create react 应用程序!

看起来我的 babel.config.js 文件被忽略了!

这是我的小项目的结构: 在此处输入图片说明

我的 html 文件

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ReactJS</title>
</head>

<body>
    <div id="app"></div>
    <script  src = 'bundle.js' ></script>
</body> 

</html>
Run Code Online (Sandbox Code Playgroud)

我的 index.js 文件:

import React from 'react';
import { render } from 'react-dom';

render(<h1>Hello World!!</h1>, document.getElementById('app')); 
Run Code Online (Sandbox Code Playgroud)

我的包json:

{
  "name": "front",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "webpack-dev-server --mode development",
    "build": "webpack-dev-server --mode production"
  },
  "dependencies": {
    "@babel/cli": "^7.10.5",
    "@babel/core": "^7.10.5",
    "@babel/plugin-proposal-class-properties": "^7.10.4",
    "@babel/preset-env": …
Run Code Online (Sandbox Code Playgroud)

html javascript reactjs yarnpkg

47
推荐指数
6
解决办法
7万
查看次数

Babel throwing 目前未启用对实验性语法“jsx”的支持

我开始写新的使用玩笑和酶反应的应用程序,当尝试使用笑话一样运行测试用例的单元测试用例"test": "jest --watch",而"test": "react-scripts test"测试通过巴贝尔去获得亚军,了解反应的语法。

并且一直在使用 babel 一步一步地进行设置,但是这个错误Support for the experimental syntax 'jsx' isn't currently enabled阻止了我走得更远。正如我在一些线程中所建议的那样,我一直在尝试npm install --save-dev @babel/plugin-transform-react-jsx并尝试将相同的插件添加到 babel 配置中,如下面的 package.json 文件所示,但仍然没有运气。 在此处输入图片说明

这是我的 package.json

{
  "name": "multitheme-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^3.9.0",
    "@material-ui/icons": "^3.0.2",
    "axios": "^0.18.0",
    "babel-plugin-transform-export-extensions": "^6.22.0",
    "jest-css-modules": "^2.1.0",
    "react": "^16.8.1",
    "react-dom": "^16.8.1",
    "react-redux": "^6.0.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.5",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs babeljs enzyme

30
推荐指数
3
解决办法
4万
查看次数

如何解决错误:“jsx”当前未启用

我是reactjs新手。我读过类似的错误帖子,语法错误:当前未启用对实验性语法“jsx”的支持 ,但无法解决我的问题

当我跑步时npm run dev

我有一个错误

ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: -..../frontend/src/index.js: Support for the experimental syntax 'jsx' isn't currently enabled (40:7):

  38 |   render() {
  39 |     return (
> 40 |       <ul>
     |       ^
  41 |         {this.state.data.map(contact => {
  42 |           return (
  43 |             <li key={contact.id}>

Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to …
Run Code Online (Sandbox Code Playgroud)

javascript npm reactjs

7
推荐指数
1
解决办法
3万
查看次数

在Laravel 5.7 React应用中,出现错误:当前未启用'classProperties'

我对React.js非常陌生。我安装了Laravel 5.7并通过运行以下命令将Vue.js支架与React交换:

php artisan preset react
Run Code Online (Sandbox Code Playgroud)

现在的问题是,我无法为组件内部的状态分配任何内容。

例如,如果我在组件内执行以下操作:

state = { foo: false };
Run Code Online (Sandbox Code Playgroud)

我得到了错误:

ERROR in ./resources/js/components/Root.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\xampp\htdocs\smart-school-v0.1\resources\js\components\Root.js: Support for the experimental syntax 'classProperties' isn't currently enabled (8:11):
Run Code Online (Sandbox Code Playgroud)

我安装了:

@babel/plugin-proposal-class-properties
Run Code Online (Sandbox Code Playgroud)

并更新.babelrc(Babel配置文件),如下所示:

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
      "@babel/plugin-proposal-class-properties"
  ]
}
Run Code Online (Sandbox Code Playgroud)

我遵循了这个,但是没有运气。

Package.json

{
    "private": true,

    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run …
Run Code Online (Sandbox Code Playgroud)

babel reactjs laravel-5.7

5
推荐指数
3
解决办法
2829
查看次数

Babel 插件类属性——React 箭头函数

我正在使用 npm 运行一个 React 项目。经过数小时的研究和试验,到处都说我必须将以下代码添加到我的“.babelrc”文件中,我的目录中没有并且无法创建:

{
  "plugins": [
    ["@babel/plugin-proposal-class-properties", { "loose": true }]
  ]
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行代码时,这会导致以下错误:

ERROR in ./src/components/NavBar/Menu.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/ymoondhra/Desktop/yt-web/src/components/NavBar/Menu.js:
Support for the experimental syntax 'classProperties' isn't currently enabled
 (20:10):
  18 |     }
  19 | 
> 20 |     fast = () => {
     |          ^
  21 |         this.speed = 100;
  22 |     }
  23 | 
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' 
section of your Babel config to enable transformation.
Run Code Online (Sandbox Code Playgroud)

plugins reactjs babeljs arrow-functions

4
推荐指数
1
解决办法
5423
查看次数