ramasilveyra / gitpkg

Publish packages as git tags
MIT License
274 stars 27 forks source link

Configuration file loading error in repo with type "module" #67

Open pdanpdan opened 9 months ago

pdanpdan commented 9 months ago

Hello.

When using gitpkg in repos with type "module" the configuration file is not loaded. I logged the error thrown when trying to load the file below. Is it possible to load .js/.cjs/.mjs?

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/pdan/Work/PDan/vue-keyboard-trap/gitpkg.config.js from .config/yarn/global/node_modules/gitpkg/build/tasks/Task/read-config.js not supported.
gitpkg.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename gitpkg.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in vue-keyboard-trap/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
eliasthompson commented 2 months ago

+1 to this issue, would love to use this package but this is blocking for esm packages that want to use the custom config options.

It seems that this line is being compiled to:

const configClass = await Promise.resolve(`${configPath}`).then(s => _interopRequireWildcard(require(s)));

which calls require(), which throws that error, which makes it always revert to the defaultConfig in the catch block. Is there any babel config you can set in babel.config.json to address this? Or else declare require() top-level somewhere?