JoshuaKGoldberg / prettier-plugin-curly

Prettier plugin to enforce consistent brace style for all control statements. 🥌
MIT License
49 stars 3 forks source link

require() of ES Module prettier-plugin-curlylib/index.js is not supported #545

Closed Tawpie closed 1 week ago

Tawpie commented 3 weeks ago

Bug Report Checklist

Expected

Plugin should run without error

Actual

Error [ERR_REQUIRE_ESM]: require() of ES Module [redacted]/node_modules/prettier-plugin-curly/lib/index.js from [redacted]/node_modules/prettier/index.js not supported. Instead change the require of [redacted]/node_modules/prettier-plugin-curly/lib/index.js in [redacted]/node_modules/prettier/index.js to a dynamic import() which is available in all CommonJS modules. at c._load (node:electron/js2c/node_init:2:13672)

Additional Info

happens with node 18.18.0 and 20.15.0

JoshuaKGoldberg commented 3 weeks ago

Works on my machine. Could you please post an isolated reproduction where I can reproduce your issues?

https://antfu.me/posts/why-reproductions-are-required

markof94 commented 1 week ago

I had this same error just now after setting up Storybook on my Nextjs project.

Reverting to ^0.1.3 stops the error from happening.

JoshuaKGoldberg commented 1 week ago

on my Nextjs project

@markof94 prove it! 🙂 (please)

markof94 commented 1 week ago

on my Nextjs project

@markof94 prove it! 🙂 (please)

Hey, I managed to recreate it on a blank Next project. I copied over the packages from my original project's package.json and the same prettier and eslint configs. Here's the repo. Hope it helps!

image

JoshuaKGoldberg commented 1 week ago

Super, thanks - I can repro with that! Much appreciated!

The root issue is roughly what Prettier is hinting: that node_modules/prettier-plugin-curly/lib/index.js has ESM imports and exports, but the project around it is not type: "module".

In other words, roughly https://github.com/JoshuaKGoldberg/create-typescript-app/blob/0a4c50f93c690af12356a9c99a7079ecb6da3a6f/docs/FAQs.md#how-can-i-add-dual-commonjs--ecmascript-modules-emit is needed. I'll do that real quick now. Thanks all!

JoshuaKGoldberg commented 1 week ago

@all-contributors please add @tawpie for bug.

🤖 Beep boop! This comment was added automatically by all-contributors-auto-action. Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed. ...and of course, thank you for contributing! 💙

allcontributors[bot] commented 1 week ago

@JoshuaKGoldberg

I've put up a pull request to add @tawpie! :tada:

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

JoshuaKGoldberg commented 1 week ago

👋 this should be fixed in prettier-plugin-curly@0.2.2. Please let me know if you have a reproduction of it still being broken. Thanks again everyone!