gpt4 book ai didi

reactjs - MIME 类型 ('text/html' ) 不可执行,并且启用了严格的 MIME 类型检查

转载 作者:行者123 更新时间:2023-12-03 13:58:00 25 4
gpt4 key购买 nike

拒绝执行来自“http://localhost:8080/edit/bundle.js”的脚本' 因为它的 MIME 类型('text/html')不可执行,并且启用了严格的 MIME 类型检查。

我正在使用react-router,并且在使用时遇到此错误

<Route path="/edit/:id" component={EditExpensePage} />

仅使用/edit 即可正常工作,但在/edit/:id 上出现错误。我不明白为什么会发生这种情况。以下是文件:这是AppRouter 文件。

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Route, Switch, Link, NavLink } from 'react-router-dom';
import Header from './../components/Header';
import ExpenseDashboardPage from './../components/ExpenseDashboardPage';
import AddExpenses from './../components/AddExpensePage';
import EditExpensePage from './../components/EditExpensePage';
import NotFoundPage from './../components/NotFoundPage';
import HelpPage from './../components/HelpPage';

const AppRouter = () => (
<BrowserRouter>
<div>
<Header />
<Switch>
<Route path="/" component={ExpenseDashboardPage} exact={true} />
<Route path="/create" component={AddExpenses} />
<Route path="/edit/:id" component={EditExpensePage} />
<Route path="/help" component={HelpPage} />
<Route component={NotFoundPage} />
</Switch>
</div>
</BrowserRouter>
);

export default AppRouter;

这是 EditExpenses 文件:

import React from 'react';

const EditExpensePage = (props) => {
console.log(props);
return (
<div>
<p>Edit your expenses Here</p>
</div>
);
}

export default EditExpensePage;

这是我的 Webpack 配置文件:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/app.js',
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}, {
test: /\.s?css$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
})
],
devtool: 'cheap-module-eval-source-map',
devServer: {
historyApiFallback: true
}
}

还有新的 HtmlWebpackPlugin 生成的 index.html 文件

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Expensify</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="bundle.js"></script>
</body>
</html>

请帮我解决这个问题。

最佳答案

尝试改变

<script type="text/javascript" src="bundle.js"></script>

<script type="text/javascript" src="/bundle.js"></script>

关于reactjs - MIME 类型 ('text/html' ) 不可执行,并且启用了严格的 MIME 类型检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49617440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com