账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    ReactDOM.render(<Index />,报错
    58
    0
    Module parse failed: Unexpected token (19:16)You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders| }|> ReactDOM.render(<Index />, document.getElementById('app'));|| export default Index;有大佬遇到过吗?说实话,我的 loader 和 babel 配置看了很久都没发现和官方有啥区别补充,loader 部分看到过类似的问题,但是修正后并没有解决附上链接:https://segmentfault.com/q/10...这个是 loader 配置 { test: /\.jsx?$/, use: { loader: 'babel-loader', // options: { // presets: [ // "@babel/preset-react", // "@babel/preset-env" // ] // } }, exclude: [ resolve('public'), resolve('node_modules'), ], include: [resolve('src')], }这个是 .babelrc 配置{ "presets": [ // "@babel/preset-env", // "@babel/preset-react", [ "@babel/preset-env", { "modules": false, "targets": { "browsers": ["Chrome >= 54"] } } ], [ "@babel/preset-react", { "pragma": "dom", // default pragma is React.createElement (only in classic runtime) "pragmaFrag": "DomFrag", // default is React.Fragment (only in classic runtime) "throwIfNamespace": false, // defaults to true "runtime": "classic" // defaults to classic // "importSource": "custom-jsx-library" // defaults to react (only in automatic runtime) } ], ["@babel/preset-typescript"] ], "plugins": [ // 解析识别 import 动态导入语法、 // "syntax-dynamic-import", ["@babel/plugin-syntax-dynamic-import"], // 隔离 import 引入对象和全局变量 ["@babel/plugin-transform-runtime"], // 优化修饰符 ["@babel/plugin-proposal-decorators", { "legacy": true }], // 箭头函数优化 ["@babel/plugin-proposal-class-properties", {"loose": true}], // 优化编译内容的打包 ["@babel/plugin-proposal-private-property-in-object", { "loose": true }], // 标记私有变量 ["@babel/plugin-proposal-private-methods", { "loose": true }] ]}
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 旧容颜. 普通会员 1楼

      报错信息表明,你在使用ReactDOM.render()方法时,传入了一个&lt;Index /&gt;,但你并没有正确地在HTML中创建或渲染这个元素。这可能是由于以下原因导致的:

      1. HTML文件中没有包含&lt;Index /&gt;元素:&lt;Index /&gt;是一个React元素,用于渲染一个div元素。如果你的HTML文件中没有包含这个元素,那么在ReactDOM.render()中将无法正确渲染它。

      2. HTML元素没有正确渲染:React的渲染过程是通过ReactDOM.render()来实现的。你需要确保你的&lt;Index /&gt;元素已经正确地在HTML中创建,或者已经通过ReactDOM.render()进行了渲染。

      3. 兼容性问题:如果你正在使用React 16或更高版本,那么这个错误可能是因为你的浏览器不支持&lt;Index /&gt;元素。你需要确保你的浏览器支持这个元素。

      4. 语法错误:如果以上问题都没有解决,那么可能是你的代码中存在语法错误。你需要检查你的代码,确保所有的语法都是正确的。

      在解决问题之前,我建议你先检查一下你的代码,看看是否有语法错误或者是否正确地创建和渲染了&lt;Index /&gt;元素。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部