Skip to content
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

Add documentation on Gulp usage #26

Closed
blakeembrey opened this issue Nov 3, 2015 · 33 comments
Closed

Add documentation on Gulp usage #26

blakeembrey opened this issue Nov 3, 2015 · 33 comments

Comments

@blakeembrey
Copy link
Member

From #24. Should also clarify that certain issues are coming from node and that this always loads tsconfig.json by default - how to use two tsconfig.json files.

@iby
Copy link

iby commented Jan 17, 2016

👍 Any notes on Gulp would make my life much prettier right now.

@blakeembrey
Copy link
Member Author

@ianbytchek What do you need specifically? Have you tried creating gulpfile.ts and going from there.

@iby
Copy link

iby commented Jan 17, 2016

I've been googling earlier on today on how to write gulp tasks straight in TS and not worry about the manual tsc step. Didn't come up with much, but found a few references that this is the place to start looking. I saw require-typescript project and your suggestion to deprecate it in favour of this one, then I saw #44, all made me a little confused. So, didn't give it a proper try yet, then this issue caught my eye.

Is it actually possible to write gulpfile in TS and execute it without compiling first? I'm not seeing how gulpfile.ts can help unless compiled first or ran not through gulp?

PS: thanks for all the cool TypeScript work. Started playing with it a few days ago, having a good time.

@blakeembrey
Copy link
Member Author

@ianbytchek Yep, definitely works. Give it a go. Gulp uses https://www.npmjs.com/package/liftoff which uses https://www.npmjs.com/package/rechoir, so .ts will automatically registry ts-node.

Edit: Sorry it's non-obvious, definitely requires a see it to believe approach 🙏

@iby
Copy link

iby commented Jan 18, 2016

@blakeembrey I'm missing something. So I installed ts-node globally, but get a bunch of errors when run gulp.

[16:07:19] Failed to load external module typescript-node/register
[16:07:19] Failed to load external module typescript-register
[16:07:19] Failed to load external module typescript-require

I tried installing typescript-register which seems to work, but I though that all three packages are deprecated in favour of this one? Did I miss a step?

@blakeembrey
Copy link
Member Author

@ianbytchek Try installing ts-node locally?

@iby
Copy link

iby commented Jan 18, 2016

I actually tried that too, didn't help. I figured that doing gulp --require ts-node/register makes the trick, but can this be automated?

@blakeembrey
Copy link
Member Author

@ianbytchek Odd, I get the message too - but the file actually does load, I'll look into this.

image

@blakeembrey
Copy link
Member Author

@ianbytchek Just realised what it was. ts-node requires typescript explicitly and without it, ts-node crashes. Make sure you install typescript, I'll improve the user-experience here since Gulp is suppressing the actual error.

@iby
Copy link

iby commented Jan 20, 2016

@blakeembrey I have it.

npm ls -g --depth 0
/usr/local/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@blakeembrey
Copy link
Member Author

Make sure you install both locally, not globally. I'll have a better error message in stderr ASAP to mitigate this in the future.

@iby
Copy link

iby commented Jan 20, 2016

Thanks, I'll give it a go now!

@iby
Copy link

iby commented Jan 21, 2016

Wow it really just works. Sorry, it still doesn't, tried it on the wrong project. Have those locally installed, any other reason why it might be failing? 😕

@blakeembrey
Copy link
Member Author

@ianbytchek Can you create a copy of the project you're using that I can replicate? That would be perfect 👍

@iby
Copy link

iby commented Jan 22, 2016

@blakeembrey try ianbytchek/guild. gulp, typescript and ts-node are peer deps.

# Install dependencies.
cd dependency
tsd install
npm install; npm install gulp; npm install ts-node; npm install typescript

// Run gulp.
cd ../build
gulp # Fails…
gulp --require ts-node/register # Succeeds…

@joeskeen
Copy link
Contributor

joeskeen commented Feb 2, 2016

I've been using TypeScript for my gulpfile.ts and this is how I got it to work. I create a gulpfile.js file containing only these two lines:

require('ts-node/register');
require('./gulpfile.ts');

Then I write all my Gulp tasks in gulpfile.ts. Works like a charm. Since ts-node doesn't compile the js file in the same directory, it doesn't clobber the gulpfile.js file.

@jednano
Copy link

jednano commented Feb 2, 2016

You shouldn't need to require ts-node/register. See this comment, which leads to these lines.

Disclaimer – I haven't tried a gulpfile.ts like this yet, but it should, theoretically, work.

@iby
Copy link

iby commented Feb 2, 2016

@joeskeen thanks, this is a better solution than doing --require ts-node/register every time. I'm curious though why it works in some cases like @blakeembrey says, but not for me.

@joeskeen
Copy link
Contributor

joeskeen commented Feb 2, 2016

@jedmao yeah, I have seen those before, but for whatever reason, I wasn't able to get it to work without adding a gulpfile.js and requiring ts-node/register. But that was a while ago, things may have changed since then; at any rate, my solution is still working for our project nicely. :)

@jednano
Copy link

jednano commented Feb 3, 2016

You boys got me all curious now, so I created gulpfile-ts, which demonstrates that the gulpfile.ts is supported out-of-the-box. It does the require('ts-node/register') for you so you don't have to!

@iby
Copy link

iby commented Feb 3, 2016

@jedmao thanks for looking into this. This is still failing on me:

ianbytchek@ibmbp:gulpfile-ts-master$ npm install
ianbytchek@ibmbp:gulpfile-ts-master$ tsd install
ianbytchek@ibmbp:gulpfile-ts-master$ gulp
[13:54:11] Failed to load external module typescript-node/register
[13:54:11] Failed to load external module typescript-register
[13:54:11] Failed to load external module typescript-require
/Users/ianbytchek/Downloads/gulpfile-ts-master/gulpfile.ts:1
(function (exports, require, module, __filename, __dirname) { import * as gulp from 'gulp';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp/bin/gulp.js:116:3)
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/liftoff/index.js:192:16)
    at module.exports (/usr/local/lib/node_modules/gulp/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3)

There is something wrong… Can you show the output of your npm ls -g --depth 0 and node -v?

@jednano
Copy link

jednano commented Feb 3, 2016

/.../GitHub/gulpfile-ts (master u=)$npm ls -g --depth 0
C:\Users\jedma\AppData\Roaming\npm
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]



/.../GitHub/gulpfile-ts (master u=)$node -v
v5.5.0


/.../GitHub/gulpfile-ts (master u=)$npm -v
3.3.12

FWIW, I'm on Windows 10.

BTW – the task was gulp hello, but I just pushed a commit so the task would be gulp, the default task.

Let me know any other way I can help.

@blakeembrey
Copy link
Member Author

@ianbytchek I finally got around to trying your demo, it appears to work fine for me.

image

@iby
Copy link

iby commented Feb 9, 2016

@blakeembrey I've figured something odd is going on. I'll try to reinstall some global packages see if that helps.

@joeskeen
Copy link
Contributor

For what it's worth, I went back and tried gulpfile.ts without gulpfile.js and it worked fine.

Edit: I thought at first it was slower, but I tried it both ways and it was about the same ~2 second delay before my gulpfile starts up

@blakeembrey
Copy link
Member Author

blakeembrey commented Feb 10, 2016

@joeskeen Using ts-node is definitely slower, see #44 for more info (not sure when I'll ever have time to actually do it).

@iby
Copy link

iby commented Mar 2, 2016

After updating gulp to 3.9.1 it works. IT WORKS!!!

kip----yesss--napoleon-dynamite-387390_200_270

@blakeembrey
Copy link
Member Author

I've made a PR to log the requireFail reason going forward. That would help here. I wanted to do logging as part of failing to register, but figured I'm already throwing errors so it'd be better to just update tooling to comply with the standard JavaScript contract here (log out the error).

@blakeembrey
Copy link
Member Author

Closing with https://github.com/TypeStrong/ts-node#gulp.

@pleerock
Copy link

pleerock commented Jun 7, 2016

I had same issue as @ianbytchek and resolved only after I updated my global gulp to 3.9.1 (previously had 3.9.0. If 3.9.1 is the minimal requirement then this needs to be specified somewhere

@HeberLZ
Copy link

HeberLZ commented Jun 21, 2016

Hi guys, i'm still having this issue when using Gulp 4, any thoughts?

@blakeembrey
Copy link
Member Author

You can always create an issue and describe the problem you're facing.

@evgenyfedorenko
Copy link

Updating gulp to 3.9.1 fixed the same I issue I had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants