React,Babel,Webpack无法解析jsx代码

webpack.config.js

module.exports = {

context: __dirname + "/app",

entry: {

javascript: "./app.js",

html: "./index.html",

},

resolve: {

extensions: ['', '.js', '.jsx']

},

output: {

filename: "app.js",

path: __dirname + "/dist",

},

module: {

loaders: [

{

test: /\.jsx?$/,

exclude: /node_modules/,

loader: "babel-loader",

},

{

test: /\.html$/,

loader: "file?name=[name].[ext]",

},

],

},

}

package.json

{

"name": "react-webpack-project",

"version": "1.0.0",

"description": "",

"main": "index.js",

"scripts": {

"test": "echo \"Error: no test specified\" && exit 1"

},

"author": "",

"license": "ISC",

"devDependencies": {

"babel": "^6.0.15",

"babel-core": "^6.0.20",

"babel-loader": "^6.0.1",

"file-loader": "^0.8.4",

"webpack": "^1.12.2"

},

"dependencies": {

"react": "^0.14.2"

}

}

app / app.js

import React from "react";

import Greeting from "./greeting";

React.render(

<Greeting name="World"/>,

document.body

);

经过四处搜寻,我看到了完全相同的问题,但似乎没有答案适用于我。运行时出现以下错误webpack

./app.js

模块构建中的错误:语法错误:path / to / project / react-webpack-project / app /

app.js:意外令牌(5:2)

React.render(

<Greeting name="World"/>,

document.body

);

我不确定为什么仍会收到此错误。我猜想这与我的webpack.config.js文件有关,但不是100%是什么问题。

回答:

首先:如果您使用的是React v ^ 0.14,则应使用React-Dom呈现代码。https://www.npmjs.com/package/react-dom

以上是 React,Babel,Webpack无法解析jsx代码 的全部内容, 来源链接: utcz.com/qa/413846.html

回到顶部