Gathering detailed insights and metrics for @reactioncommerce/babel-remove-es-create-require
Gathering detailed insights and metrics for @reactioncommerce/babel-remove-es-create-require
Gathering detailed insights and metrics for @reactioncommerce/babel-remove-es-create-require
Gathering detailed insights and metrics for @reactioncommerce/babel-remove-es-create-require
npm install @reactioncommerce/babel-remove-es-create-require
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
1 Stars
3 Commits
2 Forks
5 Watchers
1 Branches
3 Contributors
Updated on Dec 24, 2021
Latest Version
1.0.0
Package Id
@reactioncommerce/babel-remove-es-create-require@1.0.0
Unpacked Size
15.89 kB
Size
5.81 kB
File Count
6
NPM Version
6.12.0
Node Version
12.12.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
1
A Babel plugin.
If you create a Node 12 project with ECMAScript (ES) modules enabled, you will likely be doing this in a few places to import from CommonJS modules:
1import { createRequire } from "module"; 2 3const require = createRequire(import.meta.url);
This is the official way to get the require
function in a module file.
Now let's say you want to add some Jest tests. Unfortunately Jest does not yet natively parse ES modules, and it doesn't like import.meta
, so you'll need Babel configured for tests only.
Install @babel/core
, babel-jest
, @babel/preset-env
, and two plugins that take care of transforming your ES modules:
1npm i --save-dev @babel/core @babel/preset-env babel-jest babel-plugin-transform-import-meta babel-plugin-transform-es2015-modules-commonjs
The babel-plugin-transform-es2015-modules-commonjs
plugin does most of the transformation to CommonJS and babel-plugin-transform-import-meta
transforms the import.meta
code into something Jest will accept. But there's still a problem...
1const require = createRequire(import.meta.url);
Those pesky createRequire
calls are still in there, and now they're causing confusion. We no longer need them because require
will now work automatically based on the file being CommonJS.
This is where this package comes in. It does only one thing: removes all lines where you're calling createRequire
. Install it the same way you installed the other Babel plugins:
1npm i --save-dev @reactioncommerce/babel-remove-es-create-require
Then add it to your Babel config plugins list. Here's an example babel.config.js
file that should work for a Node 12 project with ES modules enabled.
1module.exports = function (api) { 2 api.cache(false); 3 4 return { 5 presets: [ 6 [ 7 "@babel/preset-env", 8 { 9 targets: { 10 node: "12" 11 } 12 } 13 ] 14 ], 15 plugins: [ 16 "babel-plugin-transform-import-meta", 17 "module:@reactioncommerce/babel-remove-es-create-require", 18 "transform-es2015-modules-commonjs" 19 ] 20 }; 21};
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
69 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More