【发布时间】:2019-10-16 00:55:15
【问题描述】:
我一直在尝试将 react js 与 webpack 一起使用,但是在执行“npm run build”时,我得到以下信息:
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import ReactDOM from 'react-dom';
| const Index = () => {
> return <div>Welcome to React!</div>;
| };
| ReactDOM.render(<Index />, document.getElementById('app'));
@ multi ./src/index.js ./src/scss/main.scss main[0]
我不知道会发生什么,当我用“npm start”启动应用程序时,如果出现文本。然后我留下我的 webpack 配置文件和 .babelrc。
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
},
}
]
},
我的代码反应:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
const Index = () => {
return <div>Welcome to React!</div>;
};
ReactDOM.render(<Index />, document.getElementById('app'));
【问题讨论】:
-
试试
use: [ { loader: "babel-loader" } ]。 -
我用它........
-
我已经尝试了所有解决问题的方法,但没有一个有效。
-
请添加你的 .babelrc 文件。