question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tsconfig paths not respected for styles

See original GitHub issue

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 angular-cli@1.3.0 the styles import of this kind is not working.

Simple reproducible example:

https://github.com/nnixaa/cli-scss-alias-issue/commit/40c33c8db58ae6f9b6c73670f0a16624428d388a

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

https://github.com/angular/angular-cli/issues/8117 (workaround used there fixes the issue) https://github.com/angular/angular-cli/issues/8036

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:24
  • Comments:8

github_iconTop GitHub Comments

8reactions
PsyGikcommented, Apr 17, 2018

Any updates/fixes/workaround on this?

3reactions
btkfrankcommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does VSCode not pick up path aliases in tsconfig?
The problem is that TypeScript's compiler preserves the paths as they are written in the source, as you can see in ...
Read more >
TSConfig Reference - Docs on every TSConfig option
This config file will include all packages under ./typings and ./vendor/types , and no packages from ./node_modules/@types . All paths are relative to...
Read more >
baseUrl in tsconfig.json is ignored when resolving Sass ...
When generating a new project via Angular CLI with ng new example --style=scss the following default configuration is generated: { "$schema": ".
Read more >
vitest-tsconfig-paths - NPM Package Overview - Socket.dev
vite-tsconfig-paths. npm codecov Code style: Prettier Donate. Give vite the ability to resolve imports using TypeScript's path mapping.
Read more >
vite-tsconfig-paths - npm
vite-tsconfig-paths. npm codecov Code style: Prettier Donate. Give vite the ability to resolve imports using TypeScript's path mapping.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found