question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: add support for the `.cjs` file extension

See original GitHub issue

Since 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cedxcommented, Jan 14, 2020

We can use a .gulp.json file at the project root to avoid the need to pass the -f option on command line:

{
  "flags": {
    "gulpfile": "gulpfile.cjs"
  }
}

I close this ticket because this solution suits me.

0reactions
phatedcommented, Jan 21, 2020

It also seems like .cjs doesn’t exist in require.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found