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

Project with type Modules skips prompt #406

Open
kevmul opened this issue Aug 22, 2022 · 2 comments
Open

Project with type Modules skips prompt #406

kevmul opened this issue Aug 22, 2022 · 2 comments

Comments

@kevmul
Copy link
Contributor

kevmul commented Aug 22, 2022

Hey everyone. I have a project that has type set to module in the package.json file.

We have been using Hygen for a while and we recently updated our entire app. The last thing we need to fix up is the Hygen generators.

It seems that with type: module in the package.json file, the prompt.js file is just skipped. This leads to errors where the templates are looking for the specific inputs that are not being requested.

Following some other issues here and there, I have tried renaming prompt.js to prompt.cjs and prompt.mjs. Both are skipped completely.

I had also tried to use export default in place of module.exports but all this doesn't matter as the file is skipped anyway.

Here is the error output

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/kmul/code/temp/_templates/fake/with-prompt/prompt.js from /Users/kmul/code/temp/node_modules/hygen/dist/prompt.js not supported.
/Users/kmul/code/temp/_templates/fake/with-prompt/prompt.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 /Users/kmul/code/temp/_templates/fake/with-prompt/prompt.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 /Users/kmul/code/temp/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead)

My question is, what do I have to do to get Hygen to work with type:module?

@kevmul
Copy link
Contributor Author

kevmul commented Aug 23, 2022

I added a PR to fix this. I believe the only issue is just adding a prompt.cjs to the hooksfiles. I would have created a test to make sure, but didn't really know how the tests work in your repo.
PR: #407

If you want a test created, let me know how / where that would be handled and I will happily create one.

@dan-turner
Copy link

This issue is now resolved and can be closed

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