[英]When I enter the terminal command "$ node fileName.js" the concole throws out a "SyntaxError: Unexpected token '<'" error
I am currently working on a cooking recipe app for a friend's website.我目前正在为朋友的网站开发烹饪食谱应用程序。 My issue is that whenever I enter "node fileName.js" into my terminal to run and check the console.log's and other outputs for my code, the terminal always trows out the following error:
我的问题是,每当我在终端中输入“node fileName.js”以运行并检查我的代码的 console.log 和其他输出时,终端总是抛出以下错误:
[Running] node "c:\Users\...\Desktop\...\src\App.js"
file:///c:/Users/.../Desktop/.../src/App.js:6
<div className="App">
^
SyntaxError: Unexpected token '<'
at Loader.moduleStrategy (node:internal/modules/esm/translators:146:18)
at async link (node:internal/modules/esm/module_job:67:21)
[Done] exited with code=1 in 0.404 seconds
My code itself works fine on http://localhost:3000/, but I was wondering if anybody has an idea how to fix a "SyntaxError: Unexpected token '<'" issue in a React project, since it gets in the way of testing/debugging code.我的代码本身在 http://localhost:3000/ 上运行良好,但我想知道是否有人知道如何解决 React 项目中的“SyntaxError: Unexpected token '<'”问题,因为它妨碍了测试/调试代码。
import './App.css';
import recipeCards from './components/functional/recipe-cards';
function App() {
return (
<div className="App">
<header className="App-header">
<p>This is a header</p>
<nav>
<p>This is a nav</p>
</nav>
</header>
<main>
<p>This is the main content</p>
<section>
<p>This is a section</p>
{recipeCards}
</section>
</main>
<footer>
<p>This is the footer</p>
</footer>
</div>
);
}
export default App;
通过在文件顶部导入 React (import React from 'react') 解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.