Upon attempting to add a new component, an error was encountered: Uncaught SyntaxError: Unexpected token export

I have created a React test project and added modules to my package.json as follows:

    {
  "name": "untitled",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-preset-node5": "^12.0.1",
    "react-scripts": "0.9.5"
  },
  "dependencies": {
    "babel-preset-stage-0": "^6.22.0",
    "history": "^4.6.1",
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-native": "^0.42.3",
    "react-router": "^4.0.0",
    "react-router-config": "^1.0.0-beta.1",
    "react-router-dom": "^4.0.0",
    "react-router-native": "^4.0.0",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.4.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "build": "babel input.js -o compiled.js"
  }
}

Along with webpack.config.js setup, which is essential for the project.

var config = {
    entry: './index.js',

    output: {
        path:'/',
        filename: 'index.js',
    },

    devServer: {
        inline: true,
        port: 8080
    },

    module: {
        loaders: [
            {
                test: /\.js?$/,
                exclude: /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', "node5", "stage-1", 'react', "stage-0"]
                }
            }
        ]
    }
};

module.exports = config;

However, when I import the Link component from react-router-native in my component, I encounter an error 'Uncaught SyntaxError: Unexpected token export'. Interestingly, this issue only arises with the Link component and not with others like Prompt, Route, or Router. Can anyone explain why it's causing a problem?

The error occurs in the following code snippet:

import React from 'react';
import { Route, Router } from 'react-router';
import { Prompt } from 'react-router';
import { Link } from 'react-router-native';

import logo from '../../logo.svg';
import './App.css';

class App extends React.Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;

Answer №1

Make sure to modify the regular expression for the test value within your webpack configuration to: test: /(\.js|\.jsx)$/

At this moment, webpack is set up to only process .js files using babel loader. However, you need to also instruct it to handle .jsx files with babel loader.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using JavaScript, transform a client's date/time string into a JSON-compatible date/time string

I need to find a way to convert a client's date/time string on a form into a JSON date/time string using JavaScript with moment.js for a Django REST API backend service. Here is the initial attempt: document.getElementById("dt_tm").value = moment(do ...

Issue with AngularJS script halting when reaching factory function that returns a promise

I have been working on a beginner project that is essentially a simple task manager (similar to those todo list projects). I created a user login page for this project and here is how it functions. There are two functions, siteLogin() for logging in, and ...

How can I fix the ReferenceError that says ToolBar is not defined?

My journey with a new Next.js project began around three days ago. After updating everything, I proceeded to include the following dependencies: yarn add @material-ui/core yarn add @mui/icons-material yarn add @mui/material This is the code snippet that r ...

React JS project experiencing issues with Material UI components not functioning properly

Here is a unique version of my app.js code: import React from "react"; import './App.css'; import {Button} from "@mui/material"; function App() { return ( <div className="App"> <h1>COVID-19 T ...

What is the best way to incorporate the .top offset into a div's height calculation?

Looking to enhance the aesthetic of this blog by adjusting the height of the #content div to match that of the last article. This will allow the background image to repeat seamlessly along the vertical axis. I attempted the following code: $(document).re ...

Building an integrated Monaco editor using Electron and AngularJS

Struggling to integrate the Monaco editor into my Electron app. Despite following electron examples, encountering persistent errors in my application. The errors I'm facing include: "loader.js:1817 Uncaught Error: Unrecognized require call" "angula ...

What is the optimal choice: Using Stack with direction="horizontal" or employing display flex in React Bootstrap?

In my opinion, the two functions may seem similar, but from personal experience I tend to favor using display flex over Stack in react boostrap. I find that display flex offers more flexibility when it comes to spacing out objects. Would anyone be able to ...

Limiting input to specific characters is effective on Chrome, but unfortunately does not function on Firefox

This code snippet is designed to restrict user input to lowercase letters from a-z, numbers from 0-9, and the dash character "-". While it functions correctly in Chrome, it does not allow any input in Firefox. What could be causing this issue? $('#sl ...

Creating a Custom Select Option Component with Ant Design Library

Is it possible to customize options in an antd select component? I have been trying to render checkboxes alongside each option, but I am only seeing the default options. Below are my 'CustomSelect' and 'CustomOption' components: // Cu ...

Define the position of a scrolled area within an HTML document to create a

In my current project, I have a scrollable area that highlights the selected div in gray. The HTML is written using Ember (hbs) and includes code to handle this functionality. Below is an example of how the div looks: Here is the corresponding HTML (hbs): ...

Tips for extracting HTML content from JSON data as valid HTML code

I am attempting to extract HTML content from a JSON object response.indexText, which has been validated with JSONLint. { "indexText": "<div id=\"content-home\"><h1> Hello World! <\/h1> <p>Some text.<\/p> ...

Upload a user-sent image to a remote SFTP server for safekeeping

Can someone help me figure out how to upload a file to an SFTP remote server using ssh2-sftp-client? I am trying to retrieve the file from the user via a post request along with the destination. To process the file, I am utilizing multer. const Client = r ...

Firefox seems to handle webpages smoothly, whereas IE struggles to display them properly

Check out the code snippet below: self.xmlHttpReq = new XMLHttpRequest(); self.xmlHttpReq.onreadystatechange = function() { if(self.xmlHttpReq.readyState == 4 && self.xmlHttpReq.status == 200) { xmlDoc = self.xmlHttpReq.response ...

Encountered a syntax hiccup in my PHP and JavaScript codes

Below is my PHP code snippet: echo ("<td><img src='edit.jpg' width='20' alt='Edit' title='EDIT DATA' onClick=\"swipe2('" + . mysql_result($result, $i, 'no'). + '');'style= ...

Steps for resetting a div's display after adjusting the device size

I have a code that displays horizontally on desktop screens and vertically on phones. It includes an x button (closebtn) that is only displayed on phones to close the menu bar. How can I automatically display it again after resizing the page back to deskto ...

What is the best way to create a continuous loop of images on a never-ending

Many discussions cover similar topics, but I have not yet found a solution to my specific question. Currently, I am working on creating a model for a website and I am interested in incorporating an infinite rotating gallery with a limited number of images ...

How can I configure nest.js to route all requests to index.html in an Angular application?

I am developing an Angular and NestJS application, and my goal is to serve the index.html file for all routes. Main.ts File: async function bootstrap() { const app = await NestFactory.create(AppModule); app.useStaticAssets(join(__dirname, '..&ap ...

Can you explain the distinction between 'rxjs/operators' and 'rxjs/internal/operators'?

When working on an Angular project, I often need to import functionalities like the Observable or switchMap operator. In such cases, there are two options available: import { switchMap } from 'rxjs/operators'; or import { switchMap } from ' ...

Angular UI and Node backend causing CORS issues

Just diving into the world of node and could use a little assistance. Encountering this error message: Access to XMLHttpRequest at 'http://localhost:3000/api/auth/signin' from origin 'http://localhost:4200' has been blocked by CORS pol ...

Having trouble deploying a Next.js application with Spline integration on Vercel

As I develop my website using spline and react-three-fiber with next.js, I have encountered an issue when deploying. The @splinetool/r3f-spline package I am using works perfectly during development and building stages, but upon deployment, I receive the ...