简体   繁体   English

您可能需要适当的加载程序来处理此文件类型。 当我在我的 create-react-app 项目中使用可选链接运算符时

[英]You may need an appropriate loader to handle this file type. When i use optional chaining operator in my create-react-app project

I learning redux right now, and i was making a project where i was doing a google oAuth authentication.我现在正在学习 redux,我正在做一个项目,我正在做一个谷歌 oAuth 身份验证。 so when i tried to use optional chaining operator i get this error.所以当我尝试使用可选链接运算符时,我得到了这个错误。

You may need an appropriate loader to handle this file type.
|           switch (_context.prev = _context.next) {
|             case 0:
>               result = res?.profileObj;
|               token = res.tokenId;

and here is the code that is giving me the error这是给我错误的代码

const googleSuccess = async (res) => {
        const result = res?.profileObj;
        const token = res?.tokenId;
        try {
            dispatch({ type: AUTH, data: { result, token } });
            history.push('/');
        } catch (error) {
            console.log(error);
        }
    };

however if i remove the ?但是,如果我删除? the error goes away and it works fine.错误消失了,它工作正常。

i am using react-google-login npm package and the googleSuccess function is passed as a props to the GoogleLogin component.我正在使用 react-google-login npm package 和 googleSuccess function 作为道具传递给 GoogleLogin 组件。

if someone could clarify it to me.如果有人可以向我澄清。 its just that sometimes, the value am assigning might not always be there and it may crash my app, and for that since optional chaining operator wasn't working i am using ternary operator(if the value to be assigned isn't present i am just assigning null using ternary operator. (and am not sure if that is okie)).只是有时,分配的值可能并不总是存在,它可能会使我的应用程序崩溃,为此,由于可选链接运算符不起作用,我正在使用三元运算符(如果要分配的值不存在,我就是只是使用三元运算符分配null 。(我不确定这是否可以))。 apologies if this question is a newbie, i just wanted to clarify myself on why i cannot use ?. operator抱歉,如果这个问题是新手,我只是想澄清一下为什么我不能使用?. operator ?. operator because i couldn't find answers anywhere else. ?. operator ,因为我在其他任何地方都找不到答案。 ps: today was the first time i was using ?. ps:今天是我第一次用?. operator操作员

This is because webpack is not able to parse the file correctly because of the new syntax.这是因为 webpack 由于新语法而无法正确解析文件。 If you have done the react-app setup from scratch using webpack.如果您已使用 webpack 从头开始完成 react-app 设置。 Then i suggest you to upgrade webpack.那我建议你升级 webpack。 If you are using create-react-app, then you should upgrade to the latest version of CRA.如果您使用的是 create-react-app,那么您应该升级到最新版本的 CRA。

Webpack Optional Chaining Issue Webpack 可选链接问题

暂无
暂无

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

相关问题 您可能需要一个合适的加载器来处理这种文件类型。 ReactJs - You may need an appropriate loader to handle this file type. ReactJs react-redux-firebase,“您可能需要适当的加载程序来处理此文件类型。” - react-redux-firebase, “You may need an appropriate loader to handle this file type.” 您可能需要一个合适的加载器来处理这种文件类型。 反应与材料用户界面 - You may need an appropriate loader to handle this file type. React & Material UI 如何修复webpack的错误:当我使用webpack加载CSS文件时,“您可能需要适当的加载器来处理此文件类型。” - How to fix the webpack bug: “you may need an appropriate loader to handle this file type.” when I useing webpack to load css files Django / React-您可能需要适当的加载程序来处理此文件类型 - Django/React - You may need an appropriate loader to handle this file type 您可能需要适当的加载程序来处理此文件类型 - React You may need an appropriate loader to handle this file type 出现错误“您可能需要适当的加载程序来处理此文件类型。” 使用 Webpack 编译 ES6 资源时 - Getting error "You may need an appropriate loader to handle this file type." when using Webpack to compile ES6 assets Webpack错误:您可能需要适当的加载程序来处理此文件类型。 | @字符集“ UTF-8”; - Webpack error: You may need an appropriate loader to handle this file type. | @charset “UTF-8”; 模块解析失败:意外的令牌(7:5)您可能需要适当的加载程序来处理此文件类型。 :Webpack,Bootstrap - Module parse failed: Unexpected token (7:5) You may need an appropriate loader to handle this file type. : Webpack, Bootstrap Vue JS 2 on rails 5.1 “您可能需要一个合适的加载器来处理这种文件类型。” - Vue JS 2 on rails 5.1 'You may need an appropriate loader to handle this file type.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM