Unexpected Token Import - Respond

I am new to reaction and webpack. Every time I run the program, I get this problem that I could not solve. I reviewed the previous questions and tried to solve them, but the problem remains the same.

webpack

module.exports = {
    entry: './src/App.js',
    output: {
        path: __dirname,
        filename: 'app.js',
},
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: 'babel',
                query: {
                    presets: ['es2015', 'stage-0', 'react']
                },
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader',
            },
        ],
    },
};

App.js

import React from 'react';
import ReactDOM from 'react-dom';

var CommentBox = React.createClass({
    render: function () {
        return (
            <div className="CommentBox">
                Hello, world!I am Comment Box.
            </div>
        );
    }
});

ReactDOM.render(<CommentBox/>, document.getElementById('app'));


package.json 
{
"name": "React-Examples",
"version": "1.0.0",
"description": "",
 "main": "index.js",
 "scripts": {
 "test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Rakesh",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.5.0",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
"dependencies": {
"react": "^15.1.0",
"react-dom": "^15.1.0"
 }}
+4
source share
1 answer

I copied your files and tried to install it.

What I came across is "npm install" to install only dependencies and not install devDependencies. It happens sometimes ... and it can be here.

Can you try

npm install --only=dev

Also you are missing one package, babel-preset-stage-0

npm install babel-preset-stage-0 --save-dev

and then try running webpack again?

0
source

Source: https://habr.com/ru/post/1653312/


All Articles