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

tsconfig paths not respected for styles #9018

Closed
nnixaa opened this issue Dec 28, 2017 · 8 comments
Closed

tsconfig paths not respected for styles #9018

nnixaa opened this issue Dec 28, 2017 · 8 comments
Labels
area: @angular-devkit/build-angular feature Issue that requests a new feature
Milestone

Comments

@nnixaa
Copy link

nnixaa commented Dec 28, 2017

So the issue is that the paths setting from the tsconfig.app.json is not respected for style files imports since the cli 1.3.0.

My setup is that I have a module inside of my project, aliased in tsconfig.app.json using:

    ...

    "paths": {
      "@core/*": [
        "./core/*"
      ]
    }

The module consists of various ts and scss files.

The files are imported as:
import { SomeClass } from '@core/module/file';

and for styles as:
@import '~@core/module/styles'; // this fails since 1.3.0

Since [email protected] the styles import of this kind is not working.

Simple reproducible example:

nnixaa/cli-scss-alias-issue@40c33c8

Versions

tested and reproducible on cli 1.3.0, 1.6.2, 1.6.3
tested and works fine on cli 1.2.6, 1.2.7

Repro steps

Observed behavior

ERROR in ./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader/lib?{"ident":"postcss","sourceMap":false}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":false,"precision":8,"includePaths":[]}!./src/styles.scss
Module build failed:
@import '~@core/module/styles'; // this fails since 1.3.0
^
      File to import not found or unreadable: ~@core/module/styles.
Parent style sheet: stdin
      in /Users/nixa/Development/Sandbox/scss-alias-tsconfig/src/styles.scss (line 2, column 1)
Error:
@import '~@core/module/styles'; // this fails since 1.3.0
^
      File to import not found or unreadable: ~@core/module/styles.
Parent style sheet: stdin
      in /Users/nixa/Development/Sandbox/scss-alias-tsconfig/src/styles.scss (line 2, column 1)
    at options.error (/Users/nixa/Development/Sandbox/scss-alias-tsconfig/node_modules/node-sass/lib/index.js:291:26)
 @ ./src/styles.scss 4:14-191
 @ multi ./src/styles.scss

Desired behavior

Should import styles correctly as per configured paths setting.

Possibly related

#8117 (workaround used there fixes the issue)
#8036

@filipesilva filipesilva added feature Issue that requests a new feature P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Dec 28, 2017
@hansl hansl removed their assignment Feb 6, 2018
@PsyGik
Copy link

PsyGik commented Apr 17, 2018

Any updates/fixes/workaround on this?

@iwantwin
Copy link

Any updates on this?

@radonirinamaminiaina
Copy link

Same problem

@lazysergey
Copy link

lazysergey commented Aug 27, 2018

still valid issue. workaround for this is to add this entry in .angular-cli.json

    {
        "apps": [{
            ...
            "stylePreprocessorOptions": {
                "includePaths": [
                    "./app/global-styles"
                ]
            },
            ...
        }]
    }

@btkfrank
Copy link

btkfrank commented Feb 6, 2019

still valid issue. workaround for this is to add this entry in .angular-cli.json

    {
        "apps": [{
            ...
            "stylePreprocessorOptions": {
                "includePaths": [
                    "./app/global-styles"
                ]
            },
            ...
        }]
    }

Do you know if there is a way to make VS Code go to definition(ctrl/cmd + click) still works?
This can fix the build issue, but I am missing go to definition

@eestein
Copy link

eestein commented Oct 1, 2019

Any news on this? The workaround does not work for me.

My tsconfig:

"paths": {
    "@projx/components": [
        "projects/projx/components/src/public_api"
    ],
    "@projx/components/*": [
        "projects/projx/components/*"
    ],
    "~@projx/components/themes/default": [
        "projects/projx/components/src/lib/styles/themes/default.scss"
    ]
}

Inside my local SCSS file:

@import '~@projx/components/themes/default';

Still, it doesn't work for the styles, only for the TS files.

@filipesilva filipesilva added area: @angular-devkit/build-angular and removed P5 The team acknowledges the request but does not plan to address it, it remains open for discussion labels Oct 8, 2019
@ngbot ngbot bot added this to the Backlog milestone Oct 8, 2019
@alan-agius4
Copy link
Collaborator

Closing as this is working as intended. TypeScript config paths are meant to work solely for TypeScript.

As suggested above you can use includePaths to shorten your SCSS import.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

10 participants