DEV Community

fujiwara.cj
fujiwara.cj

Posted on

TIL: How to use the require syntax in .mjs files

I'm looking for time part time work by the way! Email me at cpe.austria.johncarlo@gmail.com

In a tweet about kentcdodds, someone tweeted out that you can use the require syntax by importing the createRequire from the node:module API, the snippet and the tweet below is how the function is used:

But do note that it does need "module": "NodeNext" in your tsconfig.json for it to work.

Top comments (0)