Сбой сборки Webpack с использованием ["es2015", "stage-0", "реагировать"] - PullRequest
0 голосов
/ 26 апреля 2020

Я запустил базовое приложение для корзины покупок c с реактив-редуксом и Express, Webpack и MongoDB. Но когда я пытаюсь запустить webpack , я получаю сообщение об ошибке как

Web_pack_image_here

Моя конфигурация веб-пакета выглядит следующим образом

var path=require('path');
const webpack = require('webpack'); 
module.exports= {
    entry : './src/app.js',
    output : {
        filename : 'bundle.js',
        path : path.resolve(__dirname,'public')
    },
    watch: true,
    module : {
        rules : [
            {
                test :/\.js$/,
                exclude: /node_modules/,
                loader : 'babel-loader',
                query : {
                    presets : ["es2015", "stage-0", "react"] 
                }
            }
        ]
    }
} 

Мой пакет . json - как показано ниже

{
  "name": "redux-react-simple",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "webpack_dev": "webpack --mode development",
    "build": "webpack --mode production"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.9.0",
    "@babel/preset-env": "^7.9.5",
    "@babel/preset-react": "^7.9.4",
    "babel-loader": "^8.1.0",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.11"
  },
  "dependencies": {
    "babel-core": "^6.21.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "express": "^4.17.1",
    "redux": "^4.0.5"
  }
}

Мое приложение. js код файла - как показано ниже

"use strict"
import {createStore} from 'redux';
//STEP 3 define reducers
const reducer = function(state={}, action){
  switch(action.type){
    case "POST_BOOK":
      return state = action.payload;
      break;
  }
  return state
}
// STEP 1 create the store
const store = createStore(reducer);
store.subscribe(function(){
  console.log('current state is: ',
    store.getState());
  console.log('current price: ',
    store.getState().price);
})
// STEP 2 create and dispatch actions
store.dispatch({
  type:"POST_BOOK",
  payload: {
    id: 1,
    title:'this is the book title',
    description: 'this is the book description',
    price: 33.33
  }
})

Мой сервер. js файл - как показано ниже

var express = require('express');
var app = express();
var path = require('path');

app.use(express.static('public'));

app.get('/',(req,res)=>{
    res.sendFile(path.resolve(__dirname,'public','index.html'));
});

app.listen(3000,()=>{
    console.log("running at 3000")
});

Мне нужно добиться, как если бы я запустить http://localhost: 3000 Я должен увидеть

console.log('current price: ',
store.getState().price)

данных. Но мой веб-пакет выдает ошибку, пожалуйста, помогите мне исправить это.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...