qdouble / angular-webpack-starter

A complete Angular 6 and Webpack 4 starter seed with minimal and full featured branches. Full featured branch includes: Material Design 2 (Bootstrap 4 branch available as well), @ngrx, HMR, DLLs and optional use of Universal for server-side rendering - Supports AOT (offline) compilation, sync and lazy loading. Karma/Protractor for e2e/unit tests.
MIT License
882 stars 181 forks source link

Absolute paths don't work. #308

Closed dsasidhar closed 7 years ago

dsasidhar commented 7 years ago

I have tried adding support to absolute paths by changing the configuration in the webpack.config.ts: I made the following changes in webpack.config.ts:

config.resolve = {
    extensions: ['.ts', '.js', '.json'],
    modules: [path.resolve('./src'), 'node_modules']
  };

And in webpack.d.ts:

resolve?: {
    extensions?: Array<string>;
    modules?: Array<string>;
  };

I still get Cannot find module error when I try the import statment like this: import {AppComponent} from 'app/app.component':

I also tried using path.resolve(__dir, 'src') with no luck.

Can someone please help? @qdouble Is this a known issue? I couldn't find any similar issue reported here.

Zwimber commented 7 years ago

I've had this problem too.

Adding

"baseUrl": "src",

In tsconfig.json & tsconfig.webpack.json and restarting webpack solved it

dsasidhar commented 7 years ago

@Zwimber I tried your solution and it didn't work, still getting the same error.

Zwimber commented 7 years ago

Changed it to baseurl "src". You can remove the config.resolve.modules.

dsasidhar commented 7 years ago

Cannot find module 'app/app.component'. Still the same error, no use. Do you have a working example of this, with the same setup? I can't figure out why it would work for you and not for me.

dsasidhar commented 7 years ago

@qdouble @Zwimber Any luck on this? Can't really figure out what is wrong, here.

Rafi993 commented 7 years ago

@dsasidhar could you post the whole base code after you made change in a repo and paste the link here ? it would be easier to debug

Rafi993 commented 7 years ago

and using dirname not dir seems to also work. but the whole code will help to debug if any other problem if any

dsasidhar commented 7 years ago

@Rafi993 @Zwimber Please find https://github.com/dsasidhar/angular-webpack2-starter I tried your suggestions and couldn't get it to work.

dsasidhar commented 7 years ago

This is solved by this SO question: https://stackoverflow.com/questions/46467827/absolute-path-doesnt-work-in-webpack-2

The baseUrl had to be used in compilerOptions that was the mistake all along.