简体   繁体   English

当我输入终端命令“$ node fileName.js”时,concole 会抛出“SyntaxError: Unexpected token '<'”错误

[英]When I enter the terminal command "$ node fileName.js" the concole throws out a "SyntaxError: Unexpected token '<'" error

My Env.:我的环境:

  • React v17.0.2反应 v17.0.2
  • node v16.6.1节点 v16.6.1
  • npm v7.20.3 npm v7.20.3
  • VS Code VS代码
  • Windows 10视窗 10

The Problem:问题:

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 和其他输出时,终端总是抛出以下错误:

Error Message:错误信息:

[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

TLDR TLDR

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 '<'”问题,因为它妨碍了测试/调试代码。

PS: This is the content of the whole file PS:这是整个文件的内容

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.

相关问题 运行节点fileName.js命令后如何返回终端执行? - How to return to terminal execution after running node fileName.js command? 在Docker容器中运行命令&#39;node filename.js&#39; - Run command 'node filename.js' inside a Docker container 当我运行 node js 时,我收到一个错误: SyntaxError: Unexpected token &#39;&lt;&#39; - When I run node js I receive an error: SyntaxError: Unexpected token '<' SyntaxError:节点 js 中出现意外的令牌“导出”错误 - SyntaxError: Unexpected token 'export' error in node js “node filename.js”在 vs 代码中不起作用 - “node filename.js” is not working in vs code 当我把 node .\\index 我得到错误(错误未捕获的语法错误:无效或意外的令牌) - When I put node .\index I get the error (error Uncaught SyntaxError: Invalid or unexpected token) 节点(SyntaxError:意外标识符)js终端中的文件 - Node (SyntaxError: unexpected identifier ) js files in terminal Babel成功地转译了ES6代码(node.js),但是当“ npm start”执行时,它会抛出“ SyntaxError:意外的令牌导入” - Babel transpiled ES6 code (node.js) successfully, but when do “npm start” it throws “SyntaxError: Unexpected token import ” &#39;Uncaught SyntaxError: Unexpected token &lt;&#39; in Node.js - 'Uncaught SyntaxError: Unexpected token <' in Node.js SyntaxError:意外的标记const {在node.js中 - SyntaxError: Unexpected token const { in node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM