[英]Webpack regenerator compile issue for React app, help me pls
enter image description here enter image description here在此输入图片描述 在此输入图片描述
WARNING in ./src/pages/Home.jsx 41:24-43
export 'default' (imported as 'React') was not found in 'react' (possible exports: __esModule)
@ ./src/App.js 7:0-32 158:46-50
@ ./src/index.js 6:0-24 7:97-100
[1]: https://i.stack.imgur.com/0mRcJ.png
----------
I am using a lot of ES6 syntax and I realize on apple systems sometimes certain feature dont work.我使用了很多 ES6 语法,我意识到在苹果系统上有时某些功能不起作用。 So I figure this will be killing two birds with one stone.
所以我认为这将是一箭双雕。 Minimizing and optimizing.
最小化和优化。 This issue is I am unsure what the issue is here.
这个问题是我不确定这里的问题是什么。
My webpack.config.js我的 webpack.config.js
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
target: ['web', 'es5'],
entry: path.resolve(__dirname, 'src/index.js'),
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
},
mode: "development",
plugins: [new MiniCssExtractPlugin()],
module: {
rules: [
{
test:/\.js$|jsx/,
use: ["babel-loader"],
},
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader" ]
},
{
test: /\.(png|svg|jpg|jpeg|gif|mp4)$/i,
type: 'asset/resource',
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
devServer: {
static: {
directory: path.resolve(__dirname,'public') ,
},
open: true,
liveReload: true,
port:8080,
historyApiFallback:true,
},
resolve: {
extensions: ['.js', '.jsx'],
alias: {
components: path.resolve(__dirname, 'src/components'),
images: path.resolve(__dirname, 'src/images'),
pages: path.resolve(__dirname, 'src/pages'),
}
}
}
----------
My babel-config.js我的 babel-config.js
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
],
[
"@babel/plugin-transform-runtime",
{
"asyncGenerators": true,
"generators": true,
"async": true
}
],
["@babel/plugin-proposal-export-default-from"]
]
};
----------
index.js索引.js
import React from 'react';
import ReactDOM from 'react-dom';
import "regenerator-runtime/runtime.js";
import { BrowserRouter as Router } from 'react-router-dom';
import './index.scss';
import App from './App'
ReactDOM.render(
<Router>
<App />
</Router>,
document.getElementById('root')
);
----------
components Home.jsx组件 Home.jsx
import React from 'react';
import Card from "../components/Card"
const Home = ({
items,
searchValue,
setSearchValue,
onChangeSearchInput,
onAddToFavorite,
onAddToCart
} ) =>{
return (
<div className="content">
<div className="contentSearch">
<h1 className="titleContent">{searchValue ? `Поиск запроса: "${searchValue}"` : "Все кроссовки"}</h1>
<div className="searchBlock">
<img src="search.svg" alt="Search" width={14} height={14}></img>
{searchValue && <img src="clear.svg"
alt="Clear"
className="clear"
onClick={() => setSearchValue('')}
/>}
<input onChange={onChangeSearchInput} value={searchValue} placeholder="Поиск..."></input>
</div>
</div>
<div className="sneakers" >
{items
.filter((item) => item.title.toLowerCase().includes(searchValue.toLowerCase()))
.map((item, index) => (
<Card
key={index}
onFavorite={onAddToFavorite}
onPlus={onAddToCart}
{...item}
/>
))}
</div>
</div>
)
}
export default Home;
npm i regenerator-runtime
and in webpack.config.js add this setting to entry:并在 webpack.config.js 中将此设置添加到条目中:
entry: ["regenerator-runtime/runtime", "./src/index.js"],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.