Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pdanpdan opened this issue Sep 26, 2023 · 1 comment
Open

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

pdanpdan opened this issue Sep 26, 2023 · 1 comment

Comments

@pdanpdan
Copy link

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
Copy link

+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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants