Webpack:您可能需要一个合适的加载器来处理此文件类型。错误

时间:2017-08-23 11:32:34

标签: javascript reactjs webpack

我坚持这个错误:

  

您可能需要适当的加载程序来处理此文件类型。

     

从“./App”导入应用程序;

     

ReactDOM.render(,document.getElementById(“root”)); **

我已经为此尝试了每一个Stack Overflow的答案,它仍然不适用于我。

这是我的webpack.config.js文件: -

var path = require('path');
module.exports = {
    entry: './index.js',
    output: {
        path: path.join(__dirname, 'build/'),
        filename: 'index.js',
        publicPath: '/build/'
    },
    resolve: {
        modules: [__dirname, 'node_modules']
    },
    module: {
        loaders: [
            {
                test: /\.(js|jsx)$/,
                include: path.resolve(__dirname, 'src'),
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            },
            {
                test: /\.scss$/,
                loader: 'style-loader!css-loader!sass-loader'
            }
        ]
    }
};

.babelrc文件:

{
    "presets": ["es2015", "stage-0", "react"]
}

的package.json:

{
  "name": "react-webpack",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack && babel-node --presets es2015 server.js",
    "build": "webpack -d && webpack-dev-server --content-base src/ --inline --hot --port 1234 --history-api-fallback"
  },
  "author": "Manav Saxena",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.4",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-infinite-scroll-component": "^2.4.0"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "css-loader": "^0.28.5",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^0.11.2",
    "node-sass": "^4.5.3",
    "postcss-loader": "^2.0.6",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.18.2",
    "webpack": "^3.5.5",
    "webpack-dev-server": "^2.7.1"
  }
}

index.js文件:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

ReactDOM.render(<App />, document.getElementById("root"));

0 个答案:

没有答案