Reputation: 20222
I created a React application with the code in a file called App.jsx
that starts like this:
import React, { Component } from 'react';
import logo from './logo.svg';
import ReactDOM from 'react-dom';
import './App.css';
When I do npm run
I get:
> 1 | Parse Error: Line 1: Illegal import declaration
| ^
2 | for file /path/to/file/App.jsx
I looked online and it appears that the import
statement is not recognised unless I use Babel.
However, from what I understand, with the new Create React App https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html there is no need for Babel.
So what's the best way of solving this issue?
Upvotes: 3
Views: 3026
Reputation: 5398
In the .eslintrc
file, enable modules via ecmaFeatures: { modules: true }
See Illegal import declaration - Issue #2112 for additional information.
Upvotes: 1
Reputation: 11600
You don't need to add Babel to your project because it is already included in the development environment provided by create-react-app. However, you can't just run your files directly. You have to use it as it is suggested in the blog post you linked in your question.
Upvotes: 0
Reputation: 11
From the link:
Create React App uses both Webpack and Babel under the hood.
As the current browsers don't support the import statement, you have to use Babel or similar
Upvotes: 0