如何发现rollup 3.1.0的更新错误?

回答 3 浏览 2577 2022-10-14
  1. 我想安装rollup-plugin-visualizer,但它需要更新rollup。

  2. 更新了从1.8.03.1.0的rollup。

    出错了

    [!] 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.
    
  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

rollup-plugin-babel npm页面说!!

💡 This package has been deprecated and is no longer maintained. Please use @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

谁能告诉我在哪里可以找到这个错误的解决方案呢?

Garo Gabrielyan 提问于2022-10-14
我不想设置"type": "module"。Garo Gabrielyan 2022-10-14
3 个回答
#1楼 已采纳
得票数 3

我已经找到了解决方案。 首先将格式从'esm'改为'cjs',然后在rollup.config.js中改为'cjs'

export default {
    ...
    output: [
             {
                format: 'cjs',
                ...
            },
       
    ]
};

然后rollup.config.js改成了rollup.config.mjs

Garo Gabrielyan 提问于2022-10-17
这起了作用,但我最终使用了--bundleConfigAsCjs标志。这样,我可以保留默认的配置名称rollup.config.js :)widepeepohappy 2022-10-28
@widepeepohappy 谢谢你,这对我也有帮助 "build": "rm -rf dist && rollup -c --bundleConfigAsCjs && node ./scripts/copyFiles.js",.Garo Gabrielyan 2022-10-28
#2楼
得票数 2

嗨,伙计,我在运行"npm run rollup"时也有同样的问题。

RollupError。Node试图将你的配置文件作为CommonJS加载,尽管它可能是一个ES模块。要解决这个问题,请将配置的扩展名改为".mjs",在package.json文件中设置"type": "module"或者通过"-bundleConfigAsCjs"标志。

我发现了什么。

Mati 提问于2022-10-14
Mati 修改于2022-10-14
#3楼
得票数 1

如果你使用的是node v14,将其升级到v16,这在我的案例中是可行的,特别是当你在GitHub Action中运行Rollup的时候。

name: Release @vueup/vue-quill

on: 
  push: 
    branches: 
      - alpha
      - beta
      - master
    paths: 
      - 'packages/vue-quill/**'
jobs: 
  release: 
    name: Build and release
    runs-on: ubuntu-latest
    steps: 
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install root deps
        run: npm ci
      - name: Install package deps
        working-directory: packages/vue-quill
        run: npm ci
      - name: Release package
        working-directory: packages/vue-quill
        run: npx ts-node ../../scripts/release.ts vue-quill
        env: 
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
luthfimasruri 提问于2022-10-22