typescript-ruby / typescript-rails

An asset pipeline wrapper for the TypeScript language
MIT License
255 stars 30 forks source link

ts module not found issue #51

Open ziyouchutuwenwu opened 7 years ago

ziyouchutuwenwu commented 7 years ago

i removed coffie-script from gemfile

gem 'typescript-rails'

routes.rb

Rails.application.routes.draw do
  root 'welcome#index'
end

views/welcome/index.html.erb

<p id="p1">aaaaa</p>

assets/javascripts/welcome.ts

import {Greeter} from "./greeter";

window.onload = function () {
    let greeter = new Greeter();
    greeter.setName("what's this");
    document.getElementById("p1").innerHTML = greeter.greet();
};

greeter.ts in assets/javascripts/

class Greeter {
    private _greeting :string;

    setName(name :string){
        this._greeting = name;
    }

    greet() {
        return this._greeting;
    }
}

export { Greeter }

i added this to application.rb to support multi ts files compiling

Typescript::Rails::Compiler.default_options = %w(--target ES5 --noImplicitAny --module commonjs)

when i run rails in dev mode, here are the error snapshot 111

but if a copy copy class code from greeter.ts to welcome.ts, it runs ok is this a bug? if not, how can i do?

thank you very much!

cdimartino commented 6 years ago

I'm also having a terrible time getting imports to work. I've tried numerous ways of exporting/importing my internal module, and regardless of what I try, asset compilation fails. The .ts files themselves compile just fine using tsc, so this is something about how the asset pipeline is handling the compiled code.

How are people including other internal ts modules when using this gem?

Config

TypeScript::Src.use_external_tsc = true
Typescript::Rails::Compiler.default_options = %w(--target es5 --noImplicitAny --module system --sourceMap --lib es2015,dom)

auth.ts

class Auth {
...
}
export default Auth;

othercode.ts (reference path)

/// <reference path='./auth.ts' />

othercode.ts (es6 import)

import Auth from "./auth";

Error

../../../../var/folders/m2/3k5p0hsj4_j9r2x3yx9dbljmh8f8pr/T/typescript-node20180302-84896-8ydfhs.ts(2,18): error TS2307: Cannot find module 'Auth'.