If you run gulp, you will get the following error message.
Is module required for gulpfile not installed? ..
$ gulp
[22:17:15] Failed to load external module ts-node/register
[22:17:15] Failed to load external module typescript-node/register
[22:17:15] Failed to load external module typescript-register
[22:17:15] Failed to load external module typescript-require
C:\project\interview\gulpfile.ts:1
(function (exports, require, module, __filename, __dirname) { import * as gulp f rom 'gulp';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Liftoff.handleArguments (C:\Users\admin\AppData\Roaming\npm\node_modules\gu lp\bin\gulp.js:116:3)
There are 3 things you need to do to make gulp work with ES6 imports:
Rename gulpfile.js to gulpfile.babel.js
Run this command:
npm i @babel/preset-env @babel/register -D
.babelrc file to the root folder of your project with the following code in it:{
"presets": [
"@babel/preset-env"
]
}
You should now be able to use ES6 imports in your Gulp files.
Note: if you want to use TypeScript in your Gulp files instead, you should follow the steps outlined here:
1) Create a ".babelrc" file in your Projekt folder (where also all your other config files are)
Code (.babelrc)
{
"presets": ["es2015"]
}
2) Setup/Install the Babel in your NPM (see https://babeljs.io/setup). E. g. with Node:
npm install babel-preset-env --save-dev