angular-seed icon indicating copy to clipboard operation
angular-seed copied to clipboard

Gulp Typescript requires node modules

Open jerryorta opened this issue 11 years ago • 33 comments

After the gulp refactor to typescript, Terminal ( command line ) throws the following error when running gulp commands:

[03:08:39] Requiring external module ts-node/register ⨯ Unable to compile TypeScript

Installing ts-node and typescript-node fixes the issue.

I would have submitted a pull request, but not sure whether this is something that needs to be document for the developer to install globally:

```
    nom install ts-node -g
    npm install typescript-node -g
```

Or locally:

``` 
    nom install ts-node --save-dev
    npm install typescript-node --save-dev
```

I personally have to work with many repositories, so I install everything locally, and prefer as flat install as possible. But this is subjective to each developer's workflow. In this case, I would install all these separately:

```
    npm install ts-node —save-dev
    npm install typescript-node —save-dev
    npm install typescript-register —save-dev
    npm install typescript-require —save-dev
```

jerryorta avatar Oct 09 '15 08:10 jerryorta

ts-node is defined in package.json so should work. Have you run npm install ?

ludohenin avatar Oct 09 '15 08:10 ludohenin

yes. I have to run npm install twice, because ts-node is not loaded immediately after it's installed the first time. I test by deleting the node_modules folder and running npm install again.

jerryorta avatar Oct 09 '15 08:10 jerryorta

Strange, I just did exactly the same thing and it works fine.

  • OSX 10.11
  • node 4.1.1
  • npm 3.3.5

ludohenin avatar Oct 09 '15 14:10 ludohenin

Anyone else having the same issue ?

// cc: @mgechev @NathanWalker

ludohenin avatar Oct 09 '15 14:10 ludohenin

This may very well be unique to my environment. Sorry for the trouble if that is so.

Among my work and private projects, the app environments are vastly different, so I do not install anything globally.

For example I've set up my .bash_profile with this snippet:

alias npm-local='PATH=$(npm bin):$PATH'

Which allows me to run npm modules only designed to run globally - locally. I would then run tsd like this:

$ npm-local tsd install

Then in my fork of this project, I have to do this for the gulp post install scripts:


  // --------------
  // Post install
  gulp.task('install.typings', ['clean.tsd_typings'], shell.task([
    'node_modules/tsd/build/cli.js reinstall --overwrite',
    'node_modules/tsd/build/cli.js link',
    'node_modules/tsd/build/cli.js rebundle'
  ]));

It's a little bit of a pain, but keeps my projects from colliding.

jerryorta avatar Oct 09 '15 16:10 jerryorta

Hey @jerryorta-dev I can't experience that issue either.

Would you try to reproduce it with the latest changes in the repo? Thanks for reporting it!

mgechev avatar Oct 10 '15 07:10 mgechev

My specs:

  • OSX 10.10.5
  • node: 4.1.1
  • npm: 3.3.6

To reproduce:

Make sure none of the following modules are installed globally :

  • ts-node
  • typescript-node
  • install typescript-register
  • install typescript-require

Than:

  • pulled from latest master
  • run npm cache clean
  • remove node_modules
  • remove tsd_typings
  • npm install

Received the following error:

Jerrys-MacBook-Pro:angular2-seed jerryorta-dev$ gulp serve.dev
[04:17:14] Failed to load external module typescript-node/register
[04:17:14] Failed to load external module typescript-register
[04:17:14] Failed to load external module typescript-require
/Users/jerryorta-dev/Dev/UIUXEngineering/angular2-seed/gulpfile.ts:2
import * as gulp from 'gulp';
^^^^^^

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    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)
Jerrys-MacBook-Pro:angular2-seed jerryorta-dev$ 

jerryorta avatar Oct 12 '15 09:10 jerryorta

I have not experienced this issue on a clean setup.

On Fri, Oct 9, 2015 at 7:37 AM Ludovic HENIN [email protected] wrote:

Anyone else having the same issue ?

// cc: @mgechev https://github.com/mgechev @NathanWalker https://github.com/NathanWalker

— Reply to this email directly or view it on GitHub https://github.com/mgechev/angular2-seed/issues/132#issuecomment-146890488 .

NathanWalker avatar Oct 12 '15 14:10 NathanWalker

I'd close this until it becomes an issue for anyone else then. I'll investigate my set up again... re-clone the repo again, etc.

jerryorta avatar Oct 12 '15 14:10 jerryorta

Okay, thanks for that. If you encounter it again let us know.

mgechev avatar Oct 12 '15 15:10 mgechev

Also a problem for me. If I run any gulp command directly it fails. Example

$ gulp build.dev
[23:32:48] Failed to load external module typescript-node/register
[23:32:48] Requiring external module typescript-register
/Users/jesper/src/angular2-seed/node_modules/typescript-register/index.js:132
    var result = checker.emitFiles();
                         ^

TypeError: checker.emitFiles is not a function
    at compile (/Users/jesper/src/angular2-seed/node_modules/typescript-register/index.js:132:26)
    at Object.req (/Users/jesper/src/angular2-seed/node_modules/typescript-register/index.js:29:9)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Liftoff.handleArguments (/usr/local/lib/node_modules/gulp-cli/index.js:120:3)
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp-cli/node_modules/liftoff/index.js:192:16)
    at module.exports (/usr/local/lib/node_modules/gulp-cli/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3)
    at Liftoff.<anonymous> (/usr/local/lib/node_modules/gulp-cli/node_modules/liftoff/index.js:185:9)

However, npm run build.dev works just fine as expected.

My globally installed modules:

$ npm -g --depth 0 ls
/Users/jesper/.nvm/versions/node/v4.1.2/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

So, as @jerryorta-dev reports: None of the listed modules installed globally.

Note, however, that specifically using the locally installed Gulp works:

$ $(npm bin)/gulp build.dev

[23:35:14] Requiring external module ts-node/register
[23:35:17] Using gulpfile ~/src/angular2-seed/gulpfile.ts
[23:35:17] Starting 'build.dev'...
[23:35:17] Starting 'clean.dist'...
[23:35:17] Finished 'clean.dist' after 13 ms
[23:35:17] Starting 'tslint'...
[23:35:18] Finished 'tslint' after 934 ms
[23:35:18] Starting 'build.jslib.dev'...
[23:35:18] Finished 'build.jslib.dev' after 40 ms
[23:35:18] Starting 'build.sass.dev'...
[23:35:18] Finished 'build.sass.dev' after 35 ms
[23:35:18] Starting 'build.js.dev'...
[23:35:20] Finished 'build.js.dev' after 1.61 s
[23:35:20] Starting 'build.csslib.dev'...
[23:35:20] Finished 'build.csslib.dev' after 6.05 ms
[23:35:20] Starting 'build.fonts'...
[23:35:20] Finished 'build.fonts' after 7.43 ms
[23:35:20] Starting 'build.index.dev'...
[23:35:20] gulp-inject 8 files into index.html.
[23:35:20] Finished 'build.index.dev' after 31 ms
[23:35:20] Finished 'build.dev' after 2.68 s

Is this another problem, or the same as @jerryorta-dev described??

jesperronn avatar Oct 26 '15 22:10 jesperronn

+1

kamikaze avatar Dec 15 '15 09:12 kamikaze

+1

talmog avatar Dec 16 '15 21:12 talmog

You can run:

gulp build.dev

You can get the following two errors:

[12:08:04] Failed to load external module ts-node/register
[12:08:04] Failed to load external module typescript-node/register
[12:08:04] Failed to load external module typescript-register
[12:08:04] Failed to load external module typescript-require
/Users/mgechev/Projects/angular2-seed/gulpfile.ts:1
(function (exports, require, module, __filename, __dirname) { import * as gulp from 'gulp';

or

[12:08:23] Failed to load external module ts-node/register
[12:08:23] Failed to load external module typescript-node/register
[12:08:23] Requiring external module typescript-register
/Users/mgechev/Projects/angular2-seed/node_modules/typescript-register/index.js:132
    var result = checker.emitFiles();
                         ^

Just run:

npm install typescript-register ts-node

mgechev avatar Dec 17 '15 10:12 mgechev

I am facing the same issue here. How to resolve it ?

sachingk avatar Dec 30 '15 09:12 sachingk

Take a look at my comment above.

mgechev avatar Dec 30 '15 09:12 mgechev

@mgechev As far as I understand, typescript-register has been deprecated in favor of ts-node. See https://github.com/pspeter3/typescript-register/blob/master/README.md. Why do we need to install both? I think, the checker.emitFiles error comes from typescript-register. Why not just removing it completely from package.json? Is it required by something else? I removed it, and the gulp build seems to work so far...

stefanocke avatar Jan 10 '16 09:01 stefanocke

@stefanocke yep, just removed it with https://github.com/mgechev/angular2-seed/commit/60e7b38bc7a4ed4ba22e3d5c89ee03734d6c4e88.

mgechev avatar Jan 11 '16 10:01 mgechev

Second time I have to work with people to help them install all things, it takes a lot of time. Please consider to enlist all global dependencies or ensure npm install works same everywhere.

e-oz avatar Jan 24 '16 17:01 e-oz

@e-oz Agreed. I'm trying to make this more reliable and stable here: https://github.com/mgechev/angular2-seed/pull/411 Still working through it, but hopefully soon. typings is much better than tsd, and while I'm at it, I'm trying to make npm install just works without hassle.

NathanWalker avatar Jan 24 '16 17:01 NathanWalker