You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
normal gulp operation when given a .ts file when ts-node is installed
What actually happened?
[10:24:59] Requiring external module ts-node/register
.\gulpfile.ts:3
import { __awaiter, __generator, __read, __spread } from "tslib";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Module._compile (internal/modules/cjs/loader.js:891:18)
...
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 of const { 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:
src(srcFiles).pipe<NodeJS.ReadWriteStream>(newer({dest: home,ext: '.js'})).pipe<NodeJS.ReadWriteStream>(sourcemaps.init()).pipe<NodeJS.ReadWriteStream>(ts({lib: ['es2016','dom'],removeComments: true})).pipe(uglify).pipe<NodeJS.ReadWriteStream>(sourcemaps.write('.'))// sourcemap as separate file.pipe(dest(home))
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 typed import statements, then I would not need to manually provide the type to pipe<T>() to have them properly type checked.
I have tried many different combinations of values to these tsconfig.json options:
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:
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.
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: