5

I am working with the aurelia-typescript-skeleton as the base for my new project. I tried adding a new hello.ts file in src folder

export class Hello {
  sayHello(name:string) : string {
    return 'Hello ' + name;
  }
}

and referenced it in another file in the same folder as below

import {Hello} from './hello';

export class Users {
  constructor() {
    console.log(new Hello().sayHello('Test'));
  }
}

Both the files are at the same folder level. Everything works fine when I build for the first time. When I make any subsequent changes on the users.ts file, the gulp-typescript compilation keeps failing with an error I am unable to understand. The error from the typescript compiler is

> Starting 'build-system'...
> src\users.ts(4,21): error TS2307: Cannot find module 'hello'.
> TypeScript: 1 semantic error
> TypeScript: emit succeeded (with errors)
> Finished 'build-system' after 950 ms

Whenever i do a fresh gulp watch, there are no errors. The error appears when I edit/change the users.ts file. Can anyone help me understand this error? It must be something basic...

I'm on Windows 7 environment, and I get this error on 2 machines.

UPDATE:

Here is the repo to reproduce the problem. Steps to reproduce:

  1. Clone the repo, install all npm and jspm dependencies.
  2. Run gulp watch -> no errors occur for me
  3. Change users.ts file and save -> the error occurs.

UPDATE2:

Adding a clean step before build-system helps to avoid the problem. Here is the link to commit. Still I'm not sure about the actual reason of the problem at first hand.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • Please add the error message from gulp too. – MartyIX Jan 06 '16 at 09:55
  • @MartinVseticka See the console output in the question - that's what I get from the gulp task – Mikhail Shilkov Jan 06 '16 at 09:58
  • I tried to download the repo and install it [ubuntu 15.10]. The build script seems to work for me. I just had to replace `/aurelia-typescript-skeleton/jspm_packages/github/aurelia/fetch-client@0.1.1/aurelia-fetch-client.d.ts` (it contained errors) with some fixes: https://pastee.org/v5ghs My `gulp watch` output: https://pastee.org/pzskc – MartyIX Jan 06 '16 at 11:21
  • @MartinVseticka I'm on Windows, can it make a difference? My output is similar to yours for the first run, but it fails on 2nd and subsequent runs. Tested on 2 machines with same result. – Mikhail Shilkov Jan 06 '16 at 11:36
  • It's very hard to tell. I know that gulp-typescript and its incremental compilation works on Windows (we have the feature on a different project). So I'm inclined to tell, it should work on Windows. I would try to ask here https://gitter.im/Aurelia/Discuss – MartyIX Jan 06 '16 at 11:44
  • @MartinVseticka Updated the question with repo and steps to reproduce. Do you have Windows to try it? My colleague already asked on gitter, I'll post the link to SO too. Thanks for your time. – Mikhail Shilkov Jan 06 '16 at 11:48
  • You are welcome. I don't. But I'll try your repo on my Linux box once again. – MartyIX Jan 06 '16 at 11:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/99929/discussion-between-martin-vseticka-and-mikhail). – MartyIX Jan 06 '16 at 11:55

1 Answers1

0

It is because only users.ts, the changed file, is sent to subsequent TS compilation, while noResolve is enabled (in tsconfig.json).

Please see file build/tasks/build.js, task 'build-system':

.pipe(changed(paths.output, {extension: '.js'}))

What files are changed are determined (by gulp-changed) by comparing last modified time of the input files with the destination. So when you run clean or watch, which involve clean, the destination is cleaned and all the files are sent to compilation again, thus no error.

As I try the updated skeleton app (1.0.0-beta.1.2.2), this problem has been fixed.

qtuan
  • 687
  • 4
  • 10
  • So, isn't the compiler able to compile just one file? (and kind of be smart to resolve dependencies) Why did it work on ubuntu? – Mikhail Shilkov Apr 22 '16 at 17:32
  • TS indeed has compile-time [module resolution](https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Module%20Resolution.md). But since noResolve is enabled, the resolved files are NOT automatically included in compilation. – qtuan Apr 23 '16 at 11:28