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

Add support for mjs gulpfile #2019

Closed
aduh95 opened this issue Sep 24, 2017 · 9 comments
Closed

Add support for mjs gulpfile #2019

aduh95 opened this issue Sep 24, 2017 · 9 comments

Comments

@aduh95
Copy link

aduh95 commented Sep 24, 2017

Hello,

As of Node 8.5.0, we can now have native support for ESM (https://nodejs.org/en/blog/release/v8.5.0/#header-notable-changes). I know this feature is still experimental, but I think it would be nice if gulp would support it, in the same way it already supports gulpfile.babel.js.

What were you expecting to happen?

$ gulp
[16:10:25] Using gulpfile.mjs - ExperimentalWarning: The ESM module loader is experimental.
[16:10:25] Starting 'default'...
Gulp with ES module! Yeah!
[16:10:25] Finished 'default' after 1.62 ms

What actually happened?

$ gulp
[16:10:19] No gulpfile found
$ gulp --gulpfile gulpfile.mjs
.../gulpfile.mjs:1
(function (exports, require, module, __filename, __dirname) { import gulp from "gulp";
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:588:28)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at execute (/usr/local/lib/node_modules/gulp-cli/lib/versioned/^4.0.0-alpha.2/index.js:35:18)

The gulpfile I used:

import gulp from "gulp";

const testTask = () =>
  new Promise(done => {
    console.log("Gulp with ES module! Yeah!");
    done();
  });

export default testTask;

What version of gulp are you using?

$ gulp -v
[16:42:58] CLI version 1.4.0
[16:42:58] Local version 4.0.0-alpha.2

What versions of npm and node are you using?

$ node -v
v8.5.0
$ npm -v
5.3.0
$ yarn -v
1.0.2

Thank you again for your amazing work at making Gulp!

@phated
Copy link
Member

phated commented Sep 25, 2017

I'm not against this, but the way v8flags, interpret and liftoff work together don't allow for flags + extensions.

@phated phated closed this as completed Sep 25, 2017
benshine pushed a commit to benshine/sandbox that referenced this issue Jan 15, 2018
…s gulp based, and gulp is not compatible with esm, if im reading gulpjs/gulp#2019 right
@t-ricci-enhancers
Copy link

Hi @phated, will gulpfile.mjs be supported by gulp when node will release a new version with ES2015 modules without an experimental flag?

@demurgos
Copy link
Member

demurgos commented Jan 22, 2018

@t-ricci-molecle
Support for gulpfile.mjs should already be technically possible using @std/esm but it's safer to wait for native support of dynamic imports before implementing it in Gulp.

I haven't tested it, but following the example in @std/esm, you could try to have a gulpfile.js file bootstraping a gulpfile.mjs if you want to start using ESM right now.

Edit: It should be already possible to expose the programmatic API with an .mjs interface.

@phated
Copy link
Member

phated commented Jan 22, 2018

I want to support imports but I don't trust that the experimental version will ship as-is so I'm going to wait.

@phated

This comment has been minimized.

@t-ricci-enhancers

This comment has been minimized.

@phated

This comment has been minimized.

@xiaoxiangmoe

This comment has been minimized.

@gulpjs gulpjs locked and limited conversation to collaborators Jan 20, 2020
@phated
Copy link
Member

phated commented Jan 21, 2020

If you'd like to help enable .mjs support, please see gulpjs/interpret#65

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

No branches or pull requests

5 participants