2015-08-15 17 views
10

मैं इस tutorial के अनुसार webpack कॉन्फ़िगर और एक ही त्रुटि मिलती रहती है करने के लिए कोशिश कर रहा हूँ। मैं मुसीबत डिबगिंग इन 2 संदेशों हो रहा है:Webpack त्रुटि प्रतिक्रिया

ERROR in ./app.js 
Module parse failed: /path/react/react-webpack-babel/app/app.js Line 1: Unexpected reserved word 
You may need an appropriate loader to handle this file type. 
| import React from "react"; 
| import Greeting from "./greeting"; 
| 

ERROR in ./index.html 
Module parse failed: /path/react/react-webpack-babel/app/index.html Line 1: Unexpected token < 
You may need an appropriate loader to handle this file type. 
| <!DOCTYPE html> 
| <html> 
| 

यहाँ मेरी webpack.configure.js है

module.exports = { 
    context: __dirname + '/app', 
    entry: { 
    javascript: "./app.js", 
    html: "./index.html" 
    }, 
    output: { 
    filename: 'app.js', 
    path: __dirname + '/dist' 
    }, 
    loaders: [ 
    { 
     test: /\.js$/, 
     exclude: /node_modules/, 
     loaders: ['babel-loader'] 
    }, 
    { 
     test: /\.jsx$/, 
     loaders: ['babel-loader'] 
    }, 
    { 
     test: /\.html$/, 
     loader: "file?name=[name].[ext]" 
    } 
    ] 
} 

यहाँ प्रतिक्रिया है घटकों

एप्लिकेशन/greeting.js

import React from "react/addons"; 

export default React.createClass({ 
    render: function() { 
    return (
     <div className="greeting"> 
     Hello, {this.props.name}! 
     </div> 
    ); 
    }, 
}); 

एप्लिकेशन/app.js निर्भरता के साथ

import React from "react/addons"; 
import Greeting from "./greeting"; 

React.render(
    <Greeting name="World"/>, 
    document.body 
); 

एप्लिकेशन/मेरी package.json index.html

<!DOCTYPE html> 
<html> 

    <head> 
    <meta charset="utf-8"> 
    <title>Webpack + React</title> 
    </head> 

    <body></body> 

    <script src="app.js"></script> 

</html> 

मामले में यह उपयोगी है, यहाँ है

{ 
    "name": "project", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "private": true, 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "author": "Me", 
    "license": "ISC", 
    "devDependencies": { 
    "babel-core": "^5.8.22", 
    "babel-loader": "^5.3.2", 
    "file-loader": "^0.8.4", 
    "webpack": "^1.11.0" 
    }, 
    "dependencies": { 
    "react": "^0.13.3" 
    } 
} 

उत्तर

17

loaders विकल्प module में घोंसला होना चाहिए इसलिए जैसे वस्तु:

module.exports = { 
    context: __dirname + '/app', 
    entry: { 
    javascript: "./app.js", 
    html: "./index.html" 
    }, 
    output: { 
    filename: 'app.js', 
    path: __dirname + '/dist' 
    }, 
    module: { 
    loaders: [ 
     { 
     test: /\.js$/, 
     exclude: /node_modules/, 
     loaders: ['babel-loader'] 
     }, 
     { 
     test: /\.jsx$/, 
     loaders: ['babel-loader'] 
     }, 
     { 
     test: /\.html$/, 
     loader: "file?name=[name].[ext]" 
     } 
    ] 
    } 
}; 

मैं भी अंत में एक लापता सेमी-कोलन जोड़ा;)

+0

आपको बहुत बहुत धन्यवाद! मैं यह समझने की कोशिश कर रहा हूं कि गर्म मॉड्यूल प्रतिस्थापन वेबपैक के साथ कैसे काम करता है लेकिन इस भाग पर फंस गया था। धन्यवाद!!! – Mdd

+0

मैंने लोडर को आपके उत्तर के अनुसार अपनी सही स्थिति में जोड़ा है, अर्ध-रंग भी जोड़ा है, मुझे अभी भी एक ही त्रुटि मिल रही है, क्या आप जानते हैं कि यह किसी अन्य कारण से हो सकता है? –

+0

@AbhinavSingi क्या आपने npm को लोडर इंस्टॉल किया था? जैसे 'npm install --save-dev babel-loader फ़ाइल-लोडर' या बस 'npm install' mdd's' package.json' के साथ? – Almouro

1

जब मैं वाक्य रचना

import Component from './components/component'; 

मैं मॉड्यूल पार्स त्रुटि हो रही थी के साथ आयात करने गया था। इसे ठीक करने के लिए, मैं .jsx निर्दिष्ट करने के लिए था और यह

import Component from `./components/component.jsx`. 

काम किया यह एक config त्रुटि बिल्कुल नहीं थी। मैं गर्म लोडर के साथ 6 लेबल पर हूँ।

संबंधित मुद्दे