Coder Social home page Coder Social logo

Comments (8)

ahmednuaman avatar ahmednuaman commented on May 20, 2024 1

Hi @s-panferov, I have this problem. The only way to resolve it is to fallback to require. I think this is because the typescript code is compiled before it's then sent into webpack, so the compiler throws an error stating modules can't be found. Here's some code (worked around): https://github.com/ahmednuaman/redux-counter/blob/master/src/js/angular2/buttons.component.ts#L2

I'll have a poke about the loader and hopefully send a PR soon. Thanks again.

from awesome-typescript-loader.

s-panferov avatar s-panferov commented on May 20, 2024

@MrMuh hello! I've just added an example for you: https://github.com/s-panferov/awesome-typescript-loader/tree/master/examples/alias

Please note, that you need to use rewriteImports option which forces loader to rewrite import paths for you. Maybe we can throw this option out when something like microsoft/TypeScript#2338 will land.

from awesome-typescript-loader.

s-panferov avatar s-panferov commented on May 20, 2024

@MrMuh also please note, that such rewrites disable autocomplete features in IDEs right now, because it is a non-standard way of resolving modules.

IDEs will still work when you alias the root folder of your project, e.g.:

module.exports = {
    resolve: {
        extensions: ['', '.ts', '.js'],
        alias: {
            src: './src'
        }
    },
    devtool: 'source-map',
    module: {
        loaders: [
            {
                test: /\.ts$/,
                loader: 'awesome-typescript-loader?module=common'
            }
        ]
    },
    entry: {
        index: ['./index.ts']
    },
    output: {
        path: './dist',
        filename: './[name].js'
    }
};
import { Constants } from 'src/common/lib/util/constants';

console.log(Constants.Test);

You import is still remains absolute, but IDE works and you don't need rewriteImports anymore.

from awesome-typescript-loader.

alex6o avatar alex6o commented on May 20, 2024

@s-panferov thank you very much for providing the sample and for pointing out the point with the IDE support; I switched to your absolute "src" approach so I can still make use of the IDE features 👍

from awesome-typescript-loader.

raybooysen avatar raybooysen commented on May 20, 2024

Hi there

I've just hit this issue, and the example no longer exists. How can I solve this?

from awesome-typescript-loader.

s-panferov avatar s-panferov commented on May 20, 2024

@raybooysen could you please describe the problem and your setup in a new issue?

from awesome-typescript-loader.

raybooysen avatar raybooysen commented on May 20, 2024

@s-panferov just to be complete, I no longer use aliases so I don't see this issue. Apologies for not responding.

from awesome-typescript-loader.

gohilumesh avatar gohilumesh commented on May 20, 2024

I have the same problem. I am using alias in webpack and typscript always complain that it "cannot find module 'shared-ng2/checkbox'. What are my other options then using require?
Appreciate your reply.

from awesome-typescript-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.