-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
gulpfile.ts fails with any import statement #2434
Comments
ES imports are not supported. You need to use the commonjs compilation target. This is being tracked at gulpjs/interpret#65 but requires a ton of work to actually make it work because you can only import ES modules from other ES modules. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What were you expecting to happen?
normal gulp operation when given a .ts file when ts-node is installed
What actually happened?
if I tsc my gulpfile.ts, then gulp can process the transpiled output perfectly. Only if I directly give gulp the gulpfile.ts that it chokes. Flags my first statement (even if it is a comment) if my file contains any import statements.
I'm using
import { src, dest, series, parallel } from 'gulp';
(see sample below) instead ofconst { src, dest, series, parallel } = require('gulp');
because require() is a typeless nodejs function(string) => any
, losing all typing information. I can have all sorts of type errors in my gulpfile without being detected, defeating the purpose of writing it in TS.With the import statements below, VSCode instanteously detects my error:
but without typing, it took me a week to note where I went wrong.
Actually if I have changed all the
require()
statements to properly typedimport
statements, then I would not need to manually provide the type topipe<T>()
to have them properly type checked.I have tried many different combinations of values to these tsconfig.json options:
ts-node is installed locally. Package.json:
The only way out is to use gulp to transpile my gulpfile.ts into gulpfile.js and kick off a second gulp to process the output. But that sounds very complicated.
Problem has been raised on Stack Overflow for a month without receiving any comments.
Please post a sample of your gulpfile (preferably reduced to just the bit that's not working)
gulpfile.ts:
What version of gulp are you using?
What versions of npm and node are you using?
The text was updated successfully, but these errors were encountered: