如何找到 rollup 3.1.0 更新错误?

Gar*_*yan 12 javascript rollup package babeljs

  1. 我想安装rollup-plugin-visualizer,但需要更新汇总。

  2. 更新汇总从1.8.03.1.0

    出现错误

    [!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.
    
    Run Code Online (Sandbox Code Playgroud)
  3. 删除node-modules文件夹和package-lock.json并再次安装npm i

出现错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: @bet-core/ui@2.4.0
npm ERR! Found: rollup@3.1.0
npm ERR! node_modules/rollup
npm ERR!   dev rollup@"^3.1.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer rollup@">=0.60.0 <3" from rollup-plugin-babel@4.4.0
npm ERR! node_modules/rollup-plugin-babel
npm ERR!   dev rollup-plugin-babel@"^4.3.2" from the root project
Run Code Online (Sandbox Code Playgroud)

rollup-plugin-babelnpm 页面说!!!

该软件包已被弃用并且不再维护。请使用@rollup/plugin-babel。
  1. 我已经删除rollup-plugin-babel然后安装@rollup/plugin-babel. 现在我收到此错误
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.
    Original error: Cannot use import statement outside a module
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我在哪里寻找这个错误的解决方案吗?

Gar*_*yan 11

我已经找到解决方案了。首先将格式从 更改'esm''cjs'inrollup.config.js

export default {
    ...
    output: [
             {
                format: 'cjs',
                ...
            },
       
    ]
};
Run Code Online (Sandbox Code Playgroud)

然后rollup.config.js改为rollup.config.mjs

  • 这有效,但我最终使用了 `--bundleConfigAsCjs` 标志。这样,我可以保留默认配置名称“rollup.config.js”:) (4认同)
  • 如果您想要“esm”和“cjs”输出怎么办? (4认同)

Mat*_*ati 5

你好,我在运行“npm run rollup”时遇到同样的问题

RollupError:Node 尝试将您的配置文件加载为 CommonJS,即使它可能是 ES 模块。要解决此问题,请将配置的扩展名更改为“.mjs”,在 package.json 文件中设置“type”:“module”或传递“--bundleConfigAsCjs”标志。

我发现了什么: