reactjs - 无法使用自定义 next.js 和 express 服务器加载 css
问题描述
拒绝应用来自“ https://www.example.com/_next/2.83c6f8132fcdb15b2703.css ”的样式,因为它的 MIME 类型(“text/html”)不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。
handle(req, res);
});
server.get('*', (req, res) => {
return handle(req, res);
});```
解决方案
We were not aware that extract-css-chunks-webpack-plugin can take loaction and file name as well. We were only giving file name. So it was generating css on root which is not accessible by next by _next.
**Old Code**
<pre>config.plugins.push(new ExtractCssChunks({
filename: isProduction ? '[name].[hash].css' : '[name].css',
chunkFilename: isProduction ? '[id].[hash].css' : '[id].css',
ignoreOrder: true
}));</pre>
**New Code After Fixing the issue**
<pre>config.plugins.push(new ExtractCssChunks({
filename: isProduction ? 'static/css/[name].[hash].css' : 'static/css/[name].css',
chunkFilename: isProduction ? 'static/css/[id].[hash].css' : 'static/css/[id].css',
ignoreOrder: true
}));</pre>
推荐阅读
- javascript - 我可以从包含带有 JavaScript 的动态部分的简单站点生成用于电子邮件模板的静态 HTML/CSS
- r - 仅排除 NA 值而不是 R 中 lm 中的整行?
- python - 来自变量的字典内的路径
- python - 为什么我在尝试从 NSRDB API 获取数据时收到 400 错误
- spring-boot - Spring boot 2.4.5 security + devtools + vaadin 嵌入式tomcat无法反序列化会话属性
- mariadb - 在 Debian 10 上配置和调整 MariaDB
- google-cloud-platform - GCP VM 未正确安装 nVidia 驱动程序
- php - 提供一个在 Windows 中可执行的客户端工作 PHP 文件,该文件还输出目录和文件
- node.js - mongoose Schema 的变化没有反映
- swiftui - 如何在 SwiftUI 中为 TabItem 标签添加高亮显示