ReactJS Module build failed: SyntaxError: Unexpected token - reactjs

I try to make ReactJS code but it fails to compile, I am with webpack-devserver.
My terminal return me :
ERROR in ./src/App.jsx Module build failed:
SyntaxError: Unexpected token
My webpack.config, App.js and package.json seems to be good to me.
I think I have make a well appeal to my modules.
Here my App.js :
import React, { Component } from 'react';
import './App.css';
import { BrowserRouter as Router, Route, Link} from 'react-router-dom';
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Route path='/' render={
()=> {
return (<h1> Welcome Home </h1> ) ;
}
}/>
</div>
</Router>
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));
Here my webpack.config.js :
const webpack = require('webpack');
module.exports = {
devtool: 'source-map',
entry: {
app: __dirname +'/src/App.jsx'
},
output: {
path: __dirname + '/dist',
filename: 'app.bundle.js'
},
module: {
rules: {
test: /\.jsx$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: "es2015", "stage-0", "react"]
}
}
]
},
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true
}
}
]}
]},
(...)
};
My package.json :
devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-node4": "^2.1.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-router-dom": "^4.2.2",
}

Hi all I have resolve my problem by reset my code completly.
Basically, I had defaults on my webpack.config.js, littles severals errors causing crash, and I have reset my package.json and App.jsx. I have ensured the name of files and their extension follows exactly the content concerned (not js for jsx, and all).
I have create a modulate structure with component (App.jsx) and a render (index.jsx).
So here my new configuration :
webpack.config.js :
const webpack = require('webpack');
module.exports = {
devtool: 'source-map',
entry: {
app: __dirname +'/src/index.jsx'
},
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
},
module: {
rules: [ {
test: /\.js|jsx$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ["es2015", "stage-0", "react"]
}
}
]
},
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: {
modules: true
}
}
]}
]},
optimization : {
splitChunks: {
chunks: "async",
minSize: 3000,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
},
devServer: {
contentBase: __dirname +'/dist'
}
};
my package.json :
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./node_modules/.bin/nodemon ./server.js",
"build": "webpack-dev-server" ,
"watch": "webpack --watch",
"babelrc": "./node_modules/.bin/babelrc-to-install"
}
my App.jsx :
import React, { Component } from 'react';
import './App.css';
import {
BrowserRouter as Router,
Route,
Link,
NavLink,
Redirect,
Switch,
} from 'react-router-dom';
import User from './pages/user/user'
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Route path='/' render={
()=> {
return (<h1> Welcome Home </h1> ) ;
}
}/>
</div>
</Router>
);
}
}
export default App;
my index.jsx :
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
Works like a charm.

I have tried with the following code , it works fine , try changing ReactDOM.render to the following and let me know , if not working will check other faults
import React, { Component } from 'react';
import './App.css';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import { render } from 'react-dom';
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Route path='/' render={
() => {
return (<h1> Welcome Home </h1>);
}
} />
</div>
</Router>
);
}
}
render(<App />, document.getElementById('root'));

Related

React Router with deeper paths

I am trying to get an example with React Router running.
My example has the 3 following routes:
(works in browser) http://0.0.0.0:8081/one
(fails in browser) http://0.0.0.0:8081/one/two
(fails in browser) http://0.0.0.0:8081/one/two/three
All routes work with Link, but only 1. works when typing the url in the browser. When typing i.e. the 2. route in the browser, the browser console responds the following error:
GET http://0.0.0.0:8081/one/app.js net::ERR_ABORTED 404 (Not Found)
Main App class:
import * as React from 'react';
import { BrowserRouter, Switch, Route, Link } from 'react-router-dom';
import { One } from './One';
import { Two } from './Two';
import { Three } from './Three';
export class App2 extends React.Component<{}, {}> {
public render() {
return <BrowserRouter>
<ul>
<li>
<Link to='/one'>One</Link>
</li>
<li>
<Link to='/one/two'>Two</Link>
</li>
<li>
<Link to='/one/two/three'>Three</Link>
</li>
</ul>
<Switch>
<Route path='/one/two/three' component={Three} />
<Route path='/one/two' component={Two} />
<Route path='/one' component={One} />
</Switch>
</BrowserRouter>;
}
}
Class named One:
import * as React from 'react';
export class One extends React.Component<{}, {}> {
public render() {
return <div>One</div>;
}
}
Class named Two:
import * as React from 'react';
export class Two extends React.Component<{}, {}> {
public render() {
return <div>Two</div>;
}
}
Class named Three:
import * as React from 'react';
export class Three extends React.Component<{}, {}> {
public render() {
return <div>Three</div>;
}
}
Command to run the app in development mode:
"scripts": {
"develop": "webpack-dev-server --mode development --open --port 8081 --host 0.0.0.0 --config webpack.dev.config.js"
}
The Webpack configuration webpack.dev.config.js:
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const htmlPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
});
module.exports = {
entry: "./src/index.tsx",
output: {
filename: "app.js",
path: path.resolve(__dirname, "dist")
},
// Enable sourcemaps for debuggin webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts', and '.tsx' as resolvable exteensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx?$/, loader: "awesome-typescript-loader" },
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "typings-for-css-module-loader", options: { modules: true, namedExport: true, camelCase: true, localIdentName: "[name]_[local]_[hash:base64]" }}
]
},
{
test: /\.scss$/,
exclude: /\.global.scss$/,
use: [
{ loader: "style-loader" },
{ loader: "typings-for-css-modules-loader", options: { modules: true, namedExport: true, camelCase: true, localIdentName: "[local]" }},
{ loader: "postcss-loader", options: { plugins: function () { return [ require("autoprefixer") ]; }}},
{ loader: "sass-loader" }
]
},
{
test: /\.scss$/,
include: /\.global.scss$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{ loader: "postcss-loader", options: { plugins: function () { return [ require("autoprefixer") ]; }}},
{ loader: "sass-loader" }
]
}
]
},
devServer: {
historyApiFallback: true,
disableHostCheck: true
},
plugins: [
new CleanWebpackPlugin({
cleanAfterEveryBuildPatterns: ['dist']
}),
htmlPlugin
]
};
I use the following versions:
Node v13.7.0
"#types/react": "16.9.11",
"#types/react-dom": "16.9.4",
"#types/react-router-dom": "5.1.2",
"react": "16.11.0",
"react-dom": "16.11.0",
"react-router-dom": "5.1.2",
"typescript": "3.7.4",
"webpack": "4.41.2",
"webpack-cli": "3.3.10",
"webpack-dev-server": "3.9.0"
I tried to follow the examples here.
Why does only the 1. route work? Why don't the other routes 2. and 3. work?
Edit 1:
Trying to use exact does not work either. The result is the same as the above mentioned:
import * as React from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import { One } from './One';
import { Two } from './Two';
import { Three } from './Three';
export class App2 extends React.Component<{}, {}> {
public render() {
return <BrowserRouter>
<Switch>
<Route exact path='/one' component={One} />
<Route exact path='/one/two' component={Two} />
<Route exact path='/one/two/three' component={Three} />
</Switch>
</BrowserRouter>;
}
}
Edit 2:
Trying to change the order does not work either. The result is the same as the above mentioned:
import * as React from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import { One } from './One';
import { Two } from './Two';
import { Three } from './Three';
export class App2 extends React.Component<{}, {}> {
public render() {
return <BrowserRouter>
<Switch>
<Route path='/one/two/three' component={Three} />
<Route path='/one/two' component={Two} />
<Route path='/one' component={One} />
</Switch>
</BrowserRouter>;
}
}
Simply: the most specific route goes first. Just reverse your order.
As with most routers each one is checked in sequential order for a match.
Edit 1: evidence https://reacttraining.com/react-router/web/guides/primary-components
Edit 2: Your 404 error indicates to me that the issue is not the router but the server. Did you build the server or is webpack-dev-server a premade server for serving while you develop? I think you'll find that if you go to /one and click a to /one/two it will actually work.
Edit 3: Your webpack Dev server config needs something. I don't have experience with this, but here's a doc webpack.js.org/configuration/output/#outputpublicpath that I think should help.
As suggested in the comments: The final solution is adding publicPath: '/' to output in the Webpack config.
Try to use exact in your <Route/>
Because your paths always start with /one, react router only matches that part, if you want go deeper, you have to tell him exact(ly) what you want.
<Route exact path='/one' component={One} />
<Route exact path='/one/two' component={Two} />
<Route exact path='/one/two/three' component={Three} />
Here's the link to the docs

Navigate to a specific page by url in React

How do I navigate to a specific page with url in React?
I realized I've used CRA in the past and haven't really tackled this specifically.
Currently I'm rendering ReactDOM with BrowserRouter and Switch with exact path in Routes
// index.jsx
/* eslint-disable import/extensions */
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import store from './store';
import App from './app/App.jsx';
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root'),
);
// App.jsx
import React from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import Header from '../components/Header';
import HomePage from '../pages/Home';
import PlansPage from '../pages/Plans';
import NotFoundPage from '../pages/NotFound';
const App = () => (
<BrowserRouter>
<Header />
<Switch>
<Route exact path="/" component={HomePage} />
<Route exact path="/plans" component={PlansPage} />
<Route component={NotFoundPage} />
</Switch>
</BrowserRouter>
);
export default App;
// webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
devtool: false,
module: {
rules: [
{
test: /\.m?(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.scss$/,
use: [{
loader: 'style-loader',
options: {
sourceMap: true,
},
}, {
loader: 'css-loader',
options: {
sourceMap: true,
},
}, {
loader: 'sass-loader',
options: {
sourceMap: true,
},
}],
},
],
},
entry: './src/index.jsx',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js',
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
}),
new webpack.SourceMapDevToolPlugin({}),
],
};
Navigating to http://localhost:8080/plans leads to a page with Cannot GET /plans. However, clicking on a Link element navigates to that plans page without an issue.
Yeah since you're using webpack Dev Server all you have to do is add historyApiFallback=true and it'll fix you issue. You're essentially telling all routes to fall back to your index.html file. Hope that helped.

React router cannot GET any specified routes, except the root /

Here's my App.jsx that's first mounted to the DOM:
import React, { Component } from 'react';
import Home from './Home.jsx';
import Representatives from './Representatives.jsx';
import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom";
export default class App extends Component {
constructor() {
super();
this.state = {value: ''};
}
render() {
return (
<Router>
<div>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/representatives" component={Representatives} />
</Switch>
</div>
</Router>
)
}
}
And here's the representative's component:
import React, { Component } from 'react';
export default class Representatives extends Component {
constructor() {
super();
this.state = {value: ''};
}
render() {
return (
<div>
Hello World!
</div>
)
}
}
It looks exactly like examples I've seen and my webpack config looks like other's I've seen in similar posts. Any help would be greatly appreciated, I'm at 4+ hours wracking my brain
Here's my webpack config:
const path = require('path');
const SRC_DIR = path.resolve(__dirname, './src');
const BUILD_DIR = path.resolve(__dirname, './public/');
module.exports = {
mode: 'development',
entry: path.resolve(SRC_DIR, 'index.jsx'),
output: {
filename: 'bundle.js',
path: BUILD_DIR,
publicPath: '/'
},
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: [/node_modules/],
use: [{
loader: 'babel-loader',
options: { "presets": [
"#babel/env",
"#babel/react"
] }
}],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
]
}
}
I added the historyApiFallback: true, and publicPath: '/'
as recommended by another post here.
Here is the index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App/App.jsx';
ReactDOM.render(<App />, document.getElementById('root'));

Missing Loader, Webpack and React

I am building an application using Reactstrap and Webpack. I am struggling with Webpack and React. I am tring to run my react-dev server but I am running into this error in my terminal:
ericpark-macbookpro3:mvp ericpark$ npm run react-dev
> github-fetcher-fullstack-v2#1.0.0 react-dev /Users/ericpark/Desktop/mvp
> webpack -d --watch
Webpack is watching the files…
Hash: d1e3cad44a718dd4af71
Version: webpack 2.7.0
Time: 64ms
Asset Size Chunks Chunk Names
bundle.js 3.35 kB 0 [emitted] main
[0] ./react-client/src/index.jsx 298 bytes {0} [built] [failed] [1 error]
ERROR in ./react-client/src/index.jsx
Module parse failed: /Users/ericpark/Desktop/mvp/react-client/src/index.jsx Unexpected token (61:6)
You may need an appropriate loader to handle this file type.
| render() {
| return (
| <div className="App">
| <Navbar></Navbar>
| <Container>
It looks like I am missing a loader. Here is my webpack.config.js
var path = require('path');
var SRC_DIR = path.join(__dirname, '/react-client/src');
var DIST_DIR = path.join(__dirname, '/react-client/dist');
module.exports = {
entry: `${SRC_DIR}/index.jsx`,
output: {
filename: 'bundle.js',
path: DIST_DIR
},
module : {
rules: [
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
],
loaders : [
{
test : /\.jsx?/,
include : SRC_DIR,
loader : 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['env', 'react', 'es2015', 'stage-0']
}
}
]
}
};
Here is my starting file index.jsx as well:
import React, { Component } from 'react';
import Navbar from './components/Navbar.jsx';
import Login from './components/Login.jsx';
import SignUp from './components/SignUp.jsx';
import Search from './components/Search.jsx';
import ProductList from './components/ProductList.jsx';
import FavoriteList from './components/FavoriteList.jsx';
import { Route, Switch } from 'react-router-dom';
import {Container} from 'reactstrap';
import axios from 'axios';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import './App.css';
class App extends Component {
constructor() {
super();
this.state = {
query : '',
products : [
{
name: 'Samsung - Galaxy J3 with 16GB Memory Cell Phone - Silver (AT&T)',
url: 'https://api.bestbuy.com/click/-/5887123/pdp',
price: 179.99,
image: 'https://img.bbystatic.com/BestBuy_US/images/products/5887/5887123_sd.jpg',
description: 'Android 7.0 Nougat4G LTE5" HD touch screenBluetooth'
},
{
name: 'Samsung - Book Cover for Samsung Galaxy Tab S2 8 - Black',
url: 'https://api.bestbuy.com/click/-/4346001/pdp',
price: 59.99,
image: 'https://img.bbystatic.com/BestBuy_US/images/products/4346/4346001_sd.jpg',
description: 'Compatible with Samsung Galaxy Tab S2 8; polyurethane material; auto on/off function; 3 viewing angles'
},
{
name: 'Samsung - Case for Samsung Galaxy S8 - Blue/clear',
url: 'https://api.bestbuy.com/click/-/5851701/pdp',
price: 19.99,
image: 'https://img.bbystatic.com/BestBuy_US/images/products/5851/5851701_sb.jpg',
description: 'Compatible with Samsung Galaxy S8'
}
],
favorites : []
}
}
handleQuery (event) {
event.preventDefault;
this.setState({
query : event.target.value
});
console.log(event.target.value);
//POST request for searching products
// axios.post('/search', {query : this.state.query}).then(function(response){
// this.setState = {products : response};
// })
}
render() {
return (
<div className="App">
<Navbar></Navbar>
<Container>
<Switch>
<Route path='/login' component={Login}/>
<Route path='/signup' component={SignUp}/>
<Route path='/' render = {(props) =>
<div>
<Search handleQuery = {this.handleQuery.bind(this)}></Search>
<ProductList products = {this.state.products}></ProductList>
</div>
}/>
<Route path='/favorites' render = {(props) =>
<FavoriteList favorites = {this.state.favorites}></FavoriteList>
}/>
</Switch>
</Container>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('app'));
Any help would be greatly appreciated
package.json
{
"name": "github-fetcher-fullstack-v2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"react-dev": "webpack -d --watch",
"server-dev": "nodemon server/index.js"
},
"author": "Beth Johnson",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.4.5",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.23.0",
"css-loader": "^0.28.11",
"react-hot-loader": "^4.1.2",
"webpack": "^2.7.0"
},
"dependencies": {
"angular": "^1.6.3",
"body-parser": "^1.17.2",
"bootstrap": "^4.1.0",
"express": "^4.15.0",
"jquery": "^3.1.1",
"mongoose": "^4.8.6",
"mysql": "^2.13.0",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"reactstrap": "^5.0.0"
}
}
Seems like Webpack config has a small problem and jsx files are not matched with appropriate loaders.
Try test: /\.jsx?$/, and see if it works.
You can easily fix by updating your config to process both .js and .jsx files:
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
}
You can add the following snippet to the webpack configuration object.
resolve: { extensions: [".jsx", ".js"] }
In your case, you might need to use js file that I recommend this config.
module:{
rules:[{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
test: /\.jsx?$/,
exclude: /node_modules/,
}, {
test: /\.s?css$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}]
}
The config includes all loader for any file you might need, eg: js jsx css scss.

Module not found when import .jsx file

I can't find out the solution. I'm using Reactstrap (CSS framework), React, Express, and Webpack.
I was success to import App.jsx file on index.jsx. Then, I tried to import NavbarTemplate.jsx file on App.jsx by using the same way. But, it displayed error like this :
ERROR in ./client/src/components/App.jsx
Module not found: Error: Can't resolve 'NavbarTemplate.jsx' in '/Users/oprent1/v2/oprent-react/client/src/components'
# ./client/src/components/App.jsx 11:22-51
# ./client/src/index.jsx
What is wrong with my configuration ? I have provided several files that related to this below :
webpack.config.js
const path = require('path');
module.exports = {
entry: path.join(__dirname, '/client/src/index.jsx'),
output: {
path: path.join(__dirname, '/client/dist/js'),
filename: 'app.js',
},
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.join(__dirname, '/client/src'),
// loader: 'babel',
loader: 'babel-loader',
query: {
presets: ["react", "es2015"],
plugins: ["transform-class-properties"]
}
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
],
},
watch: true
};
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Bootstrap from 'bootstrap/dist/css/bootstrap.css';
import App from './components/App.jsx'; //SUCCESS when imported
ReactDOM.render(
<App />,
document.getElementById('react-app')
);
App.jsx
import React from 'react';
import NavbarTemplate from 'NavbarTemplate.jsx'; //ERROR when imported
const App = (props) => {
return (
<div>
<NavbarTemplate />
</div>
);
};
export default App;
NavbarTemplate.jsx
import React, { PropTypes } from 'react';
import { Collapse, Navbar, NavbarToggler, NavbarBrand, Nav, NavItem, NavLink } from 'reactstrap';
class NavbarTemplate extends React.Component {
constructor(props) {
super(props);
this.toggleNavbar = this.toggleNavbar.bind(this);
this.state = {
collapsed: true
};
}
toggleNavbar() {
this.setState({
collapsed: !this.state.collapsed
});
}
render() {
return (
<div>
<Navbar color="faded" light>
<NavbarToggler onClick={this.toggleNavbar} />
<Collapse className="navbar-toggleable-md" isOpen={!this.state.collapsed}>
<NavbarBrand href="/">reactstrap</NavbarBrand>
<Nav navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">Github</NavLink>
</NavItem>
</Nav>
</Collapse>
</Navbar>
</div>
);
}
}
export default NavbarTemplate;
Folder Structure
according with webpack can't find module if file named jsx if you don't want to add .jsx on your import you could add resolve: { extensions: ['.js', '.jsx'] } to your webpack.config.
// ...
module: {
loaders: [
{
test: /\.jsx?$/,
include: path.join(__dirname, '/client/src'),
// loader: 'babel',
loader: 'babel-loader',
query: {
presets: ["react", "es2015"],
plugins: ["transform-class-properties"]
}
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
]
},
resolve: {
extensions: ['.js', '.jsx']
}
// ...
To import files in the same folder you have to use
./nameOfTheFile
Instead of
nameOfTheFile
So your important statement would be
import NavbarTemplate from './NavbarTemplate.jsx';
if your App.jsx and NavbarTemplate.jsx are in the same root directory then just try
import NavbarTemplate from './NavbarTemplate';
it should work
so basically . represents the parent folder when you try to do something in cmd also.so doing ./NavbarTemplate will resolve your issue as you are importing module from the same folder
If you are using a JSX file extension, you need to import like below code,
import NavbarTemplate from './NavbarTemplate.jsx';
If you are using a JS file extension, you need to import like below code,
import NavbarTemplate from './NavbarTemplate';

Resources