You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

rollup出现Unexpected token报错,rollup-plugin-postcss插件失效求助

Rollup更新后报错及postcss插件失效问题排查

问题原因

  • 核心错误为rollup配置字段拼写错误:配置文件中插件列表的标准字段名为plugins,你的配置误写为blugins,导致rollup完全无法识别到postcss插件,遇到css类型的非JS文件时没有对应的处理逻辑,直接触发报错。
  • 次要错误为入口文件语法拼写错误:index.js中console.log误写为consol.log,会在代码运行时抛出未定义错误。

修复方法

  1. 修正rollup.config.js的字段拼写,修改后完整配置如下:
import postcss from 'rollup-plugin-postcss'

export default {
    input : 'index.js',
    output : {
        file: 'dist/bundle.js',
        format: 'esm'
    },
    plugins : [
        postcss()
    ]
}
  1. 修正index.js的语法错误,修改后完整内容如下:
import './style.css'

console.log('test')
  1. 重新执行打包命令npm run build即可正常完成打包,postcss插件也会正常处理引入的css文件。

内容的提问来源于stack exchange,提问作者Mohamed Frindi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 16:36:03