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
{{ message }}
Repository navigation
Dots in custom TypeScript gulp file names break the compiler #219
Those steps work successfully for the main gulpfile.ts and outputs this line to the console when you run gulp
Requiring external module ts-node/register
What were you expecting to happen?
After running the following command:
gulp --gulpfile customGulpFile.ts
I expect it to run Requiring external module ts-node/register like it does when compiling the main gulp file.
What actually happened?
I run this command:
gulp --gulpfile customGulpFile.ts
And I get the following error:
import * as gulp from 'gulp'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1054:16)
at Module._compile (internal/modules/cjs/loader.js:1102:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at requireOrImport (xxxxxx\node_modules\gulp\node_modules\gulp-cli\lib\shared\require-or-import.js:19:11)
at execute (xxxxxx\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:37:3)
at Liftoff.handleArguments (xxxxxx\node_modules\gulp\node_modules\gulp-cli\index.js:211:24)
changed the title [-]`gulp --gulpfile customGulpFile.ts` does not import `ts-node/register` [/-][+]`gulp --gulpfile custom.GulpFile.ts` does not import `ts-node/register` [/+]on Oct 25, 2020
changed the title [-]`gulp --gulpfile custom.GulpFile.ts` does not import `ts-node/register` [/-][+]Dots in custom gulp file names break the compiler[/+]on Oct 25, 2020
changed the title [-]Dots in custom gulp file names break the compiler[/-][+]Dots in custom TypeScript gulp file names break the compiler[/+]on Oct 25, 2020
@Dan503 I could reproduce the error of this issue. And as you said, the cause of the error is dots of the middle of the gulp file.
For gulpfile.exports.ts, rechoir, which is a library used in gulp, recognizes that its base name is gulpfile and its extension is .exports.ts.
So gulp-cli cannot solve this problem in itself. However, because rechoir receives filepath and extension candidates, we would be able to solve this problem in rechoir.
If I remember correctly, it was a design decision to handle multiple dot-separated extensions because node's module loader doesn't support it. This was done in gulpjs/rechoir#37 and might just be a bug
@sttk Oh! I remember that we didn't include it because there were other breaking changes. We should plan this for the 3.0 release of gulp-cli.
I still want to completely rewrite liftoff to fit with how people are using interpret in webpack/etc. But I haven't found the time and we are no longer receiving much money to pay me for that time.
Releasing in 3.0 is fine. This isn't a super urgent issue.
Now that I know what the problem is, I've renamed my gulp files to remove the dots in the middle of their file names and everything is working as expected now. 😊
I'll keep this issue open though since it is still a bug, just a minor one that can probably be marked as a low priority.
Activity
Dan503 commentedon Sep 29, 2020
To make the issue easier to debug I've attempted to make a failing test case in PR #220.
phated commentedon Oct 14, 2020
@sttk can you take a look at this?
sttk commentedon Oct 25, 2020
@Dan503 There was no problem when I runned #220 with
npm i -D ts-node typescript.sttk commentedon Oct 25, 2020
Furthermore,
Dan503 commentedon Oct 25, 2020
Hmmm... ok so the reduced test case appears to be working properly...
This is the project that I am having the problem in:
https://github.com/Dan503/gulp-auto-imports/tree/converting-gulp-files-to-typescript
(Note it is on the "converting-gulp-files-to-typescript" branch, not the main branch)
The
npm run generatecommand in that project runs the custom ts gulp files.The
generatecommand looks like this (the gulp files have default tasks):Using
npx gulpinstead of justgulpdoesn't help.I have "ts-node" and "typescript" installed, they are not being loaded though. I get the error as mentioned at the start of the issue.
I don't see what is breaking the compiler in that project.
Dan503 commentedon Oct 25, 2020
Ahhh I found the issue. I have a dot in the file name in my project.
I've pushed up a change in PR #220 to replicate the issue I am having.
So the real issue is that dots in the middle of custom gulp file names confuse the code used to determine what type of gulp file it is.
I'll update the issue name to reflect this.
[-]`gulp --gulpfile customGulpFile.ts` does not import `ts-node/register` [/-][+]`gulp --gulpfile custom.GulpFile.ts` does not import `ts-node/register` [/+][-]`gulp --gulpfile custom.GulpFile.ts` does not import `ts-node/register` [/-][+]Dots in custom gulp file names break the compiler[/+][-]Dots in custom gulp file names break the compiler[/-][+]Dots in custom TypeScript gulp file names break the compiler[/+]sttk commentedon Oct 25, 2020
@Dan503 I could reproduce the error of this issue. And as you said, the cause of the error is dots of the middle of the gulp file.
For
gulpfile.exports.ts, rechoir, which is a library used in gulp, recognizes that its base name isgulpfileand its extension is.exports.ts.So gulp-cli cannot solve this problem in itself. However, because rechoir receives filepath and extension candidates, we would be able to solve this problem in rechoir.
I'll address this next weekend.
phated commentedon Oct 26, 2020
If I remember correctly, it was a design decision to handle multiple dot-separated extensions because node's module loader doesn't support it. This was done in gulpjs/rechoir#37 and might just be a bug
sttk commentedon Oct 28, 2020
@phated I remember that pr, too. But I forgot that liftoff doesn't yet update rechoir to latest.
I confirmed that gulp behaved correctly about this issue by updating rechoir version of liftoff to 0.7.0.
phated commentedon Oct 30, 2020
@sttk Oh! I remember that we didn't include it because there were other breaking changes. We should plan this for the 3.0 release of gulp-cli.
I still want to completely rewrite liftoff to fit with how people are using interpret in webpack/etc. But I haven't found the time and we are no longer receiving much money to pay me for that time.
Dan503 commentedon Oct 30, 2020
Releasing in 3.0 is fine. This isn't a super urgent issue.
Now that I know what the problem is, I've renamed my gulp files to remove the dots in the middle of their file names and everything is working as expected now. 😊
I'll keep this issue open though since it is still a bug, just a minor one that can probably be marked as a low priority.