Angular-cli: No support for Webpack resolve.alias

Created on 7 Mar 2017  路  6Comments  路  Source: angular/angular-cli

Hello,

It's a copy of issue #5031, it was closed as already implemented but I couldn't manage to make it work.

Steps to reproduce:

I've added this to my tsconfig.json:

"compilerOptions": {
  "baseUrl": "src",
  "paths": {
      "shared/*": ["app/shared/*"]
  }
}

Path to the constants file: src/app/shared/constants/index.ts

When I import it as usual import { testConst } from './shared/constants/index';, it works fine:

But when I use absolute path, it crashes:
import { testConst } from 'shared/constants/index';

Webpack error:

ERROR in C:/Projects/myProject/UI/src/app/app.component.ts (2,27): Cannot find module 'shared/constants/index'.)
ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve 'shared/constants/index' in 'C:\Projects\myProject\UI\src\app'

Could someone confirm that this feature works? Does it need additional config?

Most helpful comment

Could we reopen this for support for Sass? There doesn't seem to currently be a way to alias CSS...

All 6 comments

Seems it has nothing to do with #5031. The issue definitely with WebPack config. I've looked through the sources, cli doesn't add resolve.alias in Webpack config. See here, it adds node_modules path only.
So, I decided to add my alias manually in that file and it worked.

Seems we need to expand angular-cli config for aliases. WDYT guys?

There was already discussion(#1465) regarding expending of angular-cli config and implementing this feature.

Dupe of #5031, I will followup to your question there.

Could we reopen this for support for Sass? There doesn't seem to currently be a way to alias CSS...

As @thomaswmanion said, the alias for sass is not working. This is how my path looks like now when I try to import the global style.scss file @import '../../.././styles.scss'. Looks Weird and the alias does not work for that :(

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings