{"id":17398017,"url":"https://github.com/jaydson/require-from-esm","last_synced_at":"2025-03-27T22:15:40.662Z","repository":{"id":57354250,"uuid":"186542807","full_name":"jaydson/require-from-esm","owner":"jaydson","description":"Require CJS modules from ES modules","archived":false,"fork":false,"pushed_at":"2023-01-29T01:20:34.000Z","size":3,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T16:39:31.609Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaydson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-14T04:09:29.000Z","updated_at":"2025-02-08T06:55:08.000Z","dependencies_parsed_at":"2023-02-16T22:55:13.365Z","dependency_job_id":null,"html_url":"https://github.com/jaydson/require-from-esm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydson%2Frequire-from-esm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydson%2Frequire-from-esm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydson%2Frequire-from-esm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaydson%2Frequire-from-esm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaydson","download_url":"https://codeload.github.com/jaydson/require-from-esm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245931895,"owners_count":20695964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-16T14:41:58.575Z","updated_at":"2025-03-27T22:15:40.525Z","avatar_url":"https://github.com/jaydson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# require-from-esm\n\n⚠️ Warning note ⚠ ️  \n\n1) This is very experimental  \n2) Node.js' latest version (12.0.0) is required  \n3) You should run Node.js with the `--experimental-modules` flag  \n4) You probably should run Node.js with the `--es-module-specifier-resolution=node` flag  \n\n`require-from-esm` is a small package with literally few lines aiming to provide interoperability between CJS modules and ES modules.  \nTo be more specific, `require-from-esm` let you require CJS modules with the old friend Node.js global `require()` from ES modules.  \nWith ES modules on Node.js we can use almost every feature from ECMA modules (still experimental).   \n\nExample:  \n```\nimport require from 'require-from-esm';\nimport path from 'path';\nconst mymodule = require('../../mymodule.cjs'); // You should use `../../` for local modules *\n\nconsole.log(path.normalize('/foo/bar//baz/asdf/quux/..'));\nconsole.log(mymodule);\n```\n\nFor local modules you should use `require(../../MYMODULE)` instead of `require(./MYMODULE)`.  \nWe don't have `__dirname` and `__pathname` globals when using ES modules.  \nNo solution was found to fix it until now. \nPRs are welcome.  \n\n## How to use\n1) Be sure you're using Node.js \u003e12.0.0  \n2) The flags, you should use the flags: `--experimental-modules` and `--es-module-specifier-resolution=node`  \n3) You can use npm scripts to run your app, something like this:  \n```\n  \"scripts\": {\n    \"start\": \"node --experimental-modules --es-module-specifier-resolution=node index.js\"\n  },\n```\n4) Make sure you have the `\"type\": \"module\"` on your package.json\n\nFurther reading:  \nhttps://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff  \nhttp://2ality.com/2019/04/nodejs-esm-impl.html  \nhttps://scotch.io/tutorials/new-ecmascript-modules-in-node-v12#toc-new-features-in-node-v12  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaydson%2Frequire-from-esm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaydson%2Frequire-from-esm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaydson%2Frequire-from-esm/lists"}