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

ts module not found issue #51

Open
ziyouchutuwenwu opened this issue Feb 14, 2017 · 1 comment
Open

ts module not found issue #51

ziyouchutuwenwu opened this issue Feb 14, 2017 · 1 comment

Comments

@ziyouchutuwenwu
Copy link

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
Copy link

cdimartino commented Mar 2, 2018

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'.

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

No branches or pull requests

2 participants