Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 反应js编译加载程序问题_Javascript_Reactjs - Fatal编程技术网

Javascript 反应js编译加载程序问题

Javascript 反应js编译加载程序问题,javascript,reactjs,Javascript,Reactjs,我在编译加载器时遇到了这个问题无法处理这个文件我无法弄清楚为什么它不能正常工作我有最新的加载器版本 ERROR in ./src/app/index.js Module parse failed: /var/www/reactjsbasics/src/app/index.js Unexpected token (8:3) You may need an appropriate loader to handle this file type. index.js import React f

我在编译加载器时遇到了这个问题无法处理这个文件我无法弄清楚为什么它不能正常工作我有最新的加载器版本

 ERROR in ./src/app/index.js
 Module parse failed: /var/www/reactjsbasics/src/app/index.js Unexpected token (8:3)
 You may need an appropriate loader to handle this file type.
index.js

import React from "react";
import {render} from "react-dom";

class App extends React.Component{
   render(){
    return(    
      <div>
            <h1>Hello</h1>
      </div>
    );
   }
}
render(<App/>,window.document.getElementById("app"));

   @ multi (webpack)-dev-server/client?http://localhost:8082 ./src/app/index.js
weback.config.js

var webpack=require("webpack");
 var path=require("path");
var DIST_DIR = path.resolve(__dirname,"dist");
var SRC_DIR = path.resolve(__dirname,"src");

  var config={
entry:SRC_DIR + "/app/index.js",
 output:{
 path:DIST_DIR+"/app",
 filename:"bundle.js",
 publicPath:"/app/"
},

  module:{
    loaders:[
  {
   test:"/\.js?/",
   include:SRC_DIR,
    loader:"babel-loader",
    query:{
         presets:["react","es2015","stage-2"]
        }
   }
      ]
    }
    };
module.exports = config; 

module.exports=config

根据您的webpack.cofig.js,我认为您没有导出config对象。请在webpack.config.js的底部添加这段代码

var webpack=require("webpack");
 var path=require("path");
var DIST_DIR = path.resolve(__dirname,"dist");
var SRC_DIR = path.resolve(__dirname,"src");

  var config={
entry:SRC_DIR + "/app/index.js",
 output:{
 path:DIST_DIR+"/app",
 filename:"bundle.js",
 publicPath:"/app/"
},

  module:{
    loaders:[
  {
   test:"/\.js?/",
   include:SRC_DIR,
    loader:"babel-loader",
    query:{
         presets:["react","es2015","stage-2"]
        }
   }
      ]
    }
    };
module.exports = config; 

我做了以下更改,但dit工作正常

         class app extends React.Component{
   render(){
    return(    
    <div>
        <h1>Hello</h1>
    </div>
   );
   }
  }
 render(<app/>,window.document.getElementById("app"));
失败:语法错误:意外标记,应为{(4:12)


在此之后,它已解决

如果未添加此模块,是否已在webpack.config.js中导出配置对象。exports=config;该部分已存在加载程序未编译已解决但类名如何以小写字母开头查看此信息
     import {render} from "react-dom"; 
        class fppex Extends React.Component