Home > OS >  as the code is correct i am still getting syntax error due to unknown reason?
as the code is correct i am still getting syntax error due to unknown reason?

Time:08-04

This the problem which is mostly shown by VS Code or it may sometimes shows that the import statement cannot be used out of the module.

That is an ES6 problem that can be solved in 2 ways: one by adding type as a module in package.json and other by saving the file by name of app.mjs. After that, it shows this syntax error by both methods after solving the problem in which we can not use the import statement out of the module.

SyntaxError: Unexpected token '<'
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18) 
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:483:14)
    at async link (node:internal/modules/esm/module_job:67:21)

I have been using this code:

// eslint-disable-next-line no-unused-vars
import logo from './logo.svg';
import './App.css';
import Row from './Row';
import requests from './requests';
import Banner from './Banner.js';
import Nav from './Nav';

Here starts the function code

function App() {
  return (
    
    <div className="App">
    <Nav />
            <Banner />
            <Row title="NETFLIX ORIGINALS" isLargeRow fetchUrl={requests.fetchNetflixOriginals} />
            <Row title="Trending" fetchUrl={requests.fetchTrending} />
            <Row title="Top Rated" fetchUrl={requests.fetchTopRated} />
            <Row title="Action Movies" fetchUrl={requests.fetchActionMovies} />
            <Row title="Comedy Movies" fetchUrl={requests.fetchComedyMovies} />
            <Row title="Horror Movies" fetchUrl={requests.fetchHorrorMovies} />
            <Row title="Romance Movies" fetchUrl={requests.fetchRomanceMovies} />
            <Row title="Documentaries" fetchUrl={requests.fetchDocumentaries} />
    
  
    </div>
  );
}

export default App;

CodePudding user response:

What engine did you use to start your project? CRA? Custom? What is this property "fetchUrl"? I would suggest that you comment out each item from your app's return statement and see if you can identify which one is throwing the error.

CodePudding user response:

Check node version and make sure you are using 14 which allows modules.

node --version

If it is under 14 upgrade to lts v16 version.

  • Related