[英]React/Zustand - Module parse failed: Unexpected token. You may need an appropriate loader to handle this file type
I am facing an error in my react app, not sure where the error itself is coming from and the code seems to be clean and bug-free and also following best practices.我在我的 react 应用程序中遇到错误,不确定错误本身来自何处,并且代码似乎干净且没有错误,并且遵循最佳实践。
Error Log
Failed to compile.
./src/components/CourseList.jsx 74:14
Module parse failed: Unexpected token (74:14)
You may need an appropriate loader to handle this file type.
| columnNumber: 17
| }
> }, course?.title), /*#__PURE__*/React.createElement("button", {
| className: "delete-btn",
| onClick: function onClick() {
courseList.jsx
<span className="course-title">{course?.title}</span>
<button
className="delete-btn"
onClick={() => {
removeCourse(course.id);
}}
>
Delete Course
</button>
After a really long time debugging what the issue was and so many tries, I later got what the issue was but don't understand why that itself was what was throwing the issue.在调试了很长时间并尝试了很多次之后,我后来得到了问题所在,但不明白为什么这本身就是引发问题的原因。
I simply had to change this, {course?.title}
to this {course.title}
and the code got compiled successfully without issues.我只需将{course?.title}
更改为{course.title}
代码就可以成功编译而没有问题。 Thereby, removing the ?
因此,删除?
to make it work.让它工作。
I hope this helps someone out there.我希望这可以帮助那里的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.