{"id":1707,"date":"2024-04-16T16:09:17","date_gmt":"2024-04-16T22:09:17","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=1707"},"modified":"2024-04-16T16:09:46","modified_gmt":"2024-04-16T22:09:46","slug":"requireesm-in-node-js","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/requireesm-in-node-js\/","title":{"rendered":"require(esm) in Node.js"},"content":{"rendered":"\n<p>Joyee Cheung <a href=\"https:\/\/joyeecheung.github.io\/blog\/2024\/03\/18\/require-esm-in-node-js\/\">made some waves in Node land<\/a> last month:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Since ESM was shipped in Node.js, for many years, it was possible to&nbsp;<code>import cjs<\/code>, but not possible to&nbsp;<code>require(esm)<\/code>. The frustration of&nbsp;<code>ERR_REQUIRE_ESM<\/code>&nbsp;has bothered many and probably has been the primary source of wasted hours in the Node.js ecosystem. If package authors wanted to make sure that both CJS and ESM users can consume their package, they either had to continue shipping their modules as CJS, or ship both the CJS and ESM version<\/p>\n<\/blockquote>\n\n\n\n<p>Apparently, it will <a href=\"https:\/\/github.com\/nodejs\/node\/pull\/51977#issuecomment-2007706238\">go out in v22<\/a>, which isn&#8217;t out yet but should be soon.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>It seems to me this should alleviate some of the pain the Node world is still feeling where projects and their dependencies are still a mix of both. But the true impact remains to be seen. Will you be upgrading to v22 to soothe any pain of your own? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Joyee Cheung made some waves in Node land last month: Since ESM was shipped in Node.js, for many years, it was possible to&nbsp;import cjs, but not possible to&nbsp;require(esm). The frustration of&nbsp;ERR_REQUIRE_ESM&nbsp;has bothered many and probably has been the primary source of wasted hours in the Node.js ecosystem. If package authors wanted to make sure that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1708,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[155,147],"class_list":["post-1707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-esm","tag-node"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/04\/pain-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=1707"}],"version-history":[{"count":2,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1707\/revisions"}],"predecessor-version":[{"id":1710,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/1707\/revisions\/1710"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/1708"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=1707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=1707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=1707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}