Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add support for the .cjs file extension #59

Closed
cedx opened this issue Oct 28, 2019 · 5 comments
Closed

Feature request: add support for the .cjs file extension #59

cedx opened this issue Oct 28, 2019 · 5 comments

Comments

@cedx
Copy link

cedx commented Oct 28, 2019

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.

@cedx cedx changed the title Feature request: add support the .cjs file extension Feature request: add support for the .cjs file extension Oct 28, 2019
@cedx
Copy link
Author

cedx commented 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.

@cedx cedx closed this as completed Jan 14, 2020
@phated
Copy link
Member

phated commented Jan 20, 2020

@cedx since node supports .cjs natively, I think we can set .cjs to null in the config but I still need to check.

@cedx
Copy link
Author

cedx commented Jan 20, 2020

Probably: when I tried, it worked. At least, locally (see #60).
(I closed this issue and the related PR because I had too many issues and PR open, and I wanted to do a cleanup of my GitHub account)
Thanks for your efforts on Gulp!

@phated
Copy link
Member

phated commented Jan 21, 2020

It seems that this is only supposed to work when you are executing something with the node command directly or importing a .cjs file from a .mjs file.

I'm not sure why your solution is actually working 😬

@phated
Copy link
Member

phated commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants