Feature request: add support for the `.cjs` file extension
See original GitHub issueSince Node.js 12.x (I don’t know the exact version: maybe since 12.11.0), we can use the .cjs
file extension to denote a JS file using the CommonJS module format.
The issue: if we use "type": "module"
in package.json
file, every file which extension ends with .js
is interpreted as an ES module. With this setting, Gulp fails when loading the gulpfile.js
file. The only way to force Node.js to interpret the Gulp file as a CommonJS module is to rename it as gulpfile.cjs
.
If we do this, Gulp doesn’t find anymore the gulpfile.cjs
by itself. We need to use the --gulpfile
or -f
command file, which is cumbersome.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
API - esbuild
The cjs format stands for "CommonJS" and is intended to be run in node. ... a package and adding "sideEffects": false in that...
Read more >Documentation - TypeScript 4.7
Node.js supports two extensions to help with this: .mjs and .cjs . .mjs files are always ES modules, and .cjs files are always...
Read more >CommonJS modules | Node.js v19.3.0 Documentation
When loading a file that has a different extension (e.g. .cjs ), its full name must be passed to require() , including its...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the ... reports test durations; highlights slow tests; file watcher support...
Read more >ts-node - npm
File extensions ; Skipping node_modules; Skipping pre-compiled ... ts-node supports --print ( -p ), --eval ( -e ), --require ( -r ) and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We can use a
.gulp.json
file at the project root to avoid the need to pass the-f
option on command line:I close this ticket because this solution suits me.
It also seems like
.cjs
doesn’t exist inrequire.extensions
, which this module is primarily concerned with.I don’t think we can support
.cjs
right now and the workaround will need to suffice. Sorry.