【问题标题】:Next.js error with npm dependencies that import css导入 css 的 npm 依赖项的 Next.js 错误
【发布时间】:2019-07-10 18:24:09
【问题描述】:

我有一个 next.js 项目,想使用一个组件(来自 npm),该组件在内部从 typeface-montserrat 导入。

Next.js 报错:

<path>/node_modules/typeface-montserrate/index.css:2
@font-face {
^
Syntax Error: Invalid or unexpected token

我的next.config.js如下

const withCSS = require('@zeit/next-css')

module.exports = withCSS({
  cssLoaderOptions: {
    url: false
  }   
})

【问题讨论】:

    标签: reactjs next.js


    【解决方案1】:

    您能否考虑为您的应用使用此配置来替换当前的next.config.js

    // next.config.js
    const withCSS = require('@zeit/next-css')
    module.exports = withCSS({
        cssModules: true
    })
    

    【讨论】:

    • 同样的错误(我同时安装了 url-loader 和 file-loader)。
    • 我更新了答案,如果它自己不清楚它的原因,它可能是。但这可能是在服务器模式下发生的。
    • 不幸的是,这也不起作用。我得到了同样的错误和一个额外的错误:[error] ./node_modules/typeface-montserrat/index.css ModuleParseError: Module parse failed: Unexpected character '' (1:4) 你可能需要一个合适的加载器来处理这个文件类型. (此二进制文件省略源代码)
    • 我应该在第一秒就问这个,包名和你使用的组件是什么,我会在我的机器上试一试。
    • 它来自一个私有的 npm 存储库。不公开。它是一个 .ts 组件,可以导入字体-montserrate
    猜你喜欢
    • 2018-02-27
    • 2015-11-16
    • 2013-10-06
    • 1970-01-01
    • 2019-12-13
    • 2020-04-02
    • 2022-07-14
    • 2016-02-18
    • 1970-01-01
    相关资源
    最近更新 更多