2017-06-21 66 views
0

我試圖建立反應熱,裝載機的WebPack-DEV-服務器,但我得到這個錯誤:反應熱裝載機3 - 模塊沒有找到

ERROR in ./app/index.jsx 
Module not found: Error: Can't resolve './components/App' in '/myURL/app' 

我有另一種的WebPack沒有反應,熱加工-module和我正在使用快速服務器,所以我的代碼是好的,問題是webpack配置。

這裏是我的WebPack配置與反應熱裝載機:

const path = require('path'); 
const webpack = require('webpack'); 
const SassLintPlugin = require('sasslint-webpack-plugin'); 
const ExtractTextPlugin = require('extract-text-webpack-plugin'); 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 

const extractSass = new ExtractTextPlugin({ 
    filename: '[name].[contenthash].css', 
    disable: process.env.NODE_ENV === 'development', 
}); 

module.exports = { 
    entry: [ 
    'react-hot-loader/patch', 
    // activate HMR for React 

    'webpack-dev-server/client?http://localhost:3000', 
    // bundle the client for webpack-dev-server 
    // and connect to the provided endpoint 

    'webpack/hot/only-dev-server', 
    // bundle the client for hot reloading 
    // only- means to only hot reload for successful updates 

    './app/index.jsx', 
    // the entry point of our app 
    ], 

    output: { 
    filename: '[name].js', 
    // the output bundle 

    path: path.resolve(__dirname, 'dist'), 

    publicPath: '/static/', 
    // necessary for HMR to know where to load the hot update chunks 
    }, 

    devtool: 'inline-source-map', 

    module: { 
    rules: [ 
     { 
     test: /\.jsx?$/, 
     include: path.resolve(__dirname, './app/'), 
     exclude: /node_modules/, 
     loader: 'babel-loader', 
     }, 
     { 
     test: /\.scss$/, 
     include: path.resolve(__dirname, './app/'), 
     loader: extractSass.extract({ 
      use: [ 
      { loader: 'css-loader?modules&localIdentName=[name]__[local]___[hash:base64:5]' }, 
      { loader: 'sass-loader' }, 
      ], 
      // use style-loader in development 
      fallback: 'style-loader', 
     }), 
     exclude: /node_modules/, 
     }, 
     { 
     test: /\.(eot|svg|ttf|woff|woff2)$/, 
     loader: 'file-loader?name=fonts/[name].[ext]', 
     }, 
    ], 
    }, 

    plugins: [ 
    new webpack.HotModuleReplacementPlugin(), 
    // enable HMR globally 

    new webpack.NamedModulesPlugin(), 
    // prints more readable module names in the browser console on HMR updates 

    new webpack.NoEmitOnErrorsPlugin(), 
    // do not emit compiled assets that include errors 
    new SassLintPlugin({ 
     configFile: '.sass-lint.yml', 
     context: [path.resolve(__dirname, './app/')], 
     ignoreFiles: [], 
     ignorePlugins: [], 
     glob: '**/*.s?(a|c)ss', 
     quiet: false, 
     failOnWarning: false, 
     failOnError: true, 
     testing: false, 
    }), 
    extractSass, 
    new HtmlWebpackPlugin({ 
     title: 'Contactto Master', 
     template: 'app/index-template.html', 
     minify: { 
     collapseWhitespace: process.env.NODE_ENV === 'production', 
     }, 
    }), 
    ], 

    devServer: { 
    host: 'localhost', 
    port: 3000, 

    historyApiFallback: true, 
    // respond to 404s with index.html 

    hot: true, 
    // enable HMR on the server 
    }, 
}; 

所以我index.jsx是:

import React from 'react'; 
import { render } from 'react-dom'; 
import { BrowserRouter } from 'react-router-dom'; 
import App from './components/App'; 

render(
    <BrowserRouter> 
    <App /> 
    </BrowserRouter>, 
document.getElementById('app')); 

而且我App.jsx是:

import React from 'react'; 
import Header from './header/Header'; 
import Main from './main/Main'; 
import Sidebar from './sidebar/Sidebar'; 
import style from './App.scss'; 

const App =() => (
    <div className={style.app}> 
    <Header /> 
    <Sidebar /> 
    <Main /> 
    </div> 
); 

export default App; 

任何人都可以幫助我嗎?

在此先感謝。

回答