Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Add createRequireFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Jul 19, 2018
1 parent 49791b4 commit a4f15c5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion proposals/esm-in-js-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ import { importCommonJS } from 'module';
importCommonJS(import.meta, './commonjs-file.js');
```
### `.cjs`
### `createRequireFunction`
See [nodejs/node#19360](https://github.com/nodejs/node/pull/19360):
```js
import { createRequireFunction } from 'module';
const require = createRequireFunction(new URL(import.meta.url));
const x = require('./commonjs-file.js');
```
### `.cjs` file extension
If a user wants to use the `import` statement to import a CommonJS file, that file needs to have a `.cjs` extension. This would allow intermixing of ESM `.js` files and CommonJS `.cjs` files, and potentially the use of CommonJS in browser environments. The `.cjs` extension would map to `application/node`, even on the Web.
Expand Down

0 comments on commit a4f15c5

Please sign in to comment.