【问题标题】:Not able to load css with custom next.js and express server无法使用自定义 next.js 和 express 服务器加载 css
【发布时间】:2020-04-08 14:31:28
【问题描述】:

拒绝应用来自 'https://www.example.com/_next/2.83c6f8132fcdb15b2703.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。

            handle(req, res);
        });


        server.get('*', (req, res) => {
            return handle(req, res);
        });```

【问题讨论】:

  • 也许您可以添加有关该问题的更多信息。另外,您能否确保 css 文件不为空?
  • 您是在 localhost 还是在某个地方的 prod env 上收到此错误?
  • 请提供您代码的完整sn-p

标签: reactjs express next.js


【解决方案1】:
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>

【讨论】:

    猜你喜欢
    • 2023-03-24
    • 2021-07-23
    • 2021-03-04
    • 2019-04-20
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 2021-04-09
    • 2019-03-25
    相关资源
    最近更新 更多