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.

Investigate if .cjs extension support is needed.

See original GitHub issue

From #59, we believed that .cjs extension support was needed, but I think that was due to not properly supporting the ESM syntax. With the work done in gulp-cli by @snoak, we can import ESM modules.

Given that, I only added support for .mjs in #65 and I wanted to open this to investigate if we actually need to support the .cjs extension.

If we end up needing to support it, I’ve put in place the architecture to support & test the extension on all versions of node.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
snoackcommented, Jun 3, 2020

Node.js considers a script an ES module if it either has the file extension .mjs, or if it has the file extension .js and is located in a package that declares "type": "module" in its package.json.

Node.js considers a script a CommonJS module if it either has the file extension .cjs, or if it has the file extension .js and is not located in a package that declares "type": "module" in its package.json.

So if a package uses "type": "module" but for whatever reason sticks to CommonJS for their Gulpfile that file would have to be named gulpfile.cjs.

1reaction
phatedcommented, Aug 2, 2020

@anshumanv Can you explain a little more? node.js supports “fall through” when requiring files that don’t have an extension registered, so wouldn’t .cjs just be loaded normally as a .js file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What the heck are CJS, AMD, UMD, and ESM in Javascript?
My goal is to help readers recognize when they see them in the wild . CJS. CJS is short for CommonJS. Here is...
Read more >
What does it take to support Node.js ESM? – The Guild
I have worked on all The Guild's libraries and graphql-js to support ESM. Here is how you can do it too.
Read more >
How to Create a Hybrid NPM Module for ESM and CommonJS.
Creating a single NPM module that works in all environments.
Read more >
How do I import an ES6 JavaScript module in my VS Code ...
Yes, this is a pain. To be specific, you can develop and debug extensions using es6 modules in vscode, but you cannot deploy...
Read more >
Config Files - Babel.js
files, with the following extensions: .json , .js , .cjs , .mjs . ... New in Babel 7.x, Babel has a concept of...
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