I have configured a gulpfile.ts
for my project based on this example from GitHub found here. (I won't be sharing my exact gulpfile.ts
as it is similar, just slightly more complex)
Every time I run a gulp task, I encounter these 4 errors:
[11:53:23] Failed to load external module ts-node/register
[11:53:23] Failed to load external module typescript-node/register
[11:53:23] Failed to load external module typescript-register
[11:53:23] Failed to load external module typescript-require
To address this, I decided to include ts-node
as a local dev-dependency. (Installing it globally did not resolve the issue)
After performing npm install
and running a gulp task, I then started encountering TypeScript errors like this
gulpfile.ts (19,23): Cannot find name 'require'. (2304)
Despite finding no solutions online, I discovered a workaround while examining various sample gulpfile.ts
files. By adding this line:
declare var __dirname, require;
at the beginning of my gulpfile.ts
, the issue was resolved and I no longer received error messages. However, I am aware that this may be considered a makeshift solution.
Now, my question is: Is this an acceptable approach for setting up a gulpfile.ts
?
I also explored gulpclass files with typings and such, but I feel that might be excessive for a simple build file. Do you have any recommendations? What are the recommended best practices in this scenario?