thepassle / barrel-begone

50 stars 1 forks source link

Error with commonjs dependencies #6

Closed jorgecasar closed 5 months ago

jorgecasar commented 5 months ago

Using commander breaks the tool. It load a module file that import a commonjs one. Maybe adding @rollup/plugin-commonjs could support commonjs dependencies

🛢️ BARREL BEGONE 🛢️

Analyzing the following entrypoints based on the "exports" field in package.json:
- ".": "./src/index.js"

.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/parseAst.js:337
        base = Object.assign(new Error(base.message), base);
                             ^

Error [RollupError]: "default" is not exported by "node_modules/commander/index.js", imported by "node_modules/commander/esm.mjs".
    at error (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
    at Module.error (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:12781:16)
    at Module.traceVariable (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:13218:29)
    at ModuleScope.findVariable (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:11635:39)
    at Identifier.bind (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:7217:40)
    at VariableDeclarator.bind (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:4641:23)
    at VariableDeclaration.bind (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:4637:28)
    at ExportNamedDeclaration.bind (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:9642:27)
    at Program.bind (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:4637:28)
    at Module.bindReferences (.npm/_npx/051184ea0da1632e/node_modules/rollup/dist/es/shared/node-entry.js:12777:18)
{
  binding: 'default',
    code: 'MISSING_EXPORT',
      exporter: '[project-path]/node_modules/commander/index.js',
        id: '[project-path]/node_modules/commander/esm.mjs',
          url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module',
            pos: 7,
              loc: {
    column: 7,
      file: '[project-path]/node_modules/commander/esm.mjs',
        line: 1
  },
  frame: "1: import commander from './index.js';\n" +
    '          ^\n' +
    '2: \n' +
    '3: // wrapper to provide named exports for ESM.',
    watchFiles: [...]
}
thepassle commented 5 months ago

You can add custom plugins yourself via

barrel-begone.config.js:

import commonjs from '@rollup/plugin-commonjs';

export default {
  rollup: {
    plugins:[commonjs()]
  }
}

I don't think the barrel file analysis will work on commonjs modules though, because it only checks import/export, but at least you should be able to get the module graph size

jorgecasar commented 5 months ago

It's not working neither with the plugin.

Thanks for your answer and I hope all libraries move to esm to make our life easier.