angular-cli: Style with ~path is not resolved correctly

Hi! I noticed that I cannot build my app properly on Windows, the problem seems to lie in ~ import in sass file (bootstrap specifically), the resolved path looks broken because it is doubled, take a look at the log

I guess the problem was caused by this code https://github.com/angular/angular-cli/commit/9caa7ca#diff-aa06fda1fc53d1b1e6d1259f3cf4ca2d . The resolved path for fonts becomes c:\vhosts\frontend-client\src\c:vhosts�rontend-clientnode_modules�ootstrap-sass ssets�onts�ootstrapglyphicons-halflings-regular.eot

Versions

Angular CLI: 1.6.3
Node: 8.9.4
OS: win32 x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.2
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.3
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.6.2
webpack: 3.10.0

Repro steps

  1. install @angular/cli@1.6.3
  2. create new project with scss styles
  3. install bootstrap@3.3.7 and bootstrap-sass@3.3.7
  4. in src/styles.scss set $icon-font-path: '~bootstrap-sass/assets/fonts/bootstrap/'; at the top
  5. then below add @import "~bootstrap-sass/assets/stylesheets/bootstrap";
  6. try to ng serve or ng build

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 not found: Error: Can't resolve './c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot' in 'c:\vhosts\frontend-client\src'
resolve './c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot' in 'c:\vhosts\frontend-client\src'
  using description file: c:\vhosts\frontend-client\package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: c:\vhosts\frontend-client\package.json (relative path: ./src)
    using description file: c:\vhosts\frontend-client\package.json (relative path: ./src/c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot.js doesn't exist
      as directory
        c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot doesn't exist
[c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot]
[c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot.ts]
[c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot.js]
[c:\vhosts\frontend-client\src\c:vhostsrontend-clientnode_modulesootstrap-sass
ssetsontsootstrapglyphicons-halflings-regular.eot]
 @ ./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 7:4344-4479 7:4510-4645
 @ ./src/styles.scss
 @ multi ./src/styles.scss

Desired behavior

Successful build

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 15
  • Comments: 19 (5 by maintainers)

Most upvoted comments

This sounds like something that could have easily been prevented by an automated tests, merely trying to build a trivial off-the-shelf Angular Material app (the kind of app you would build following Angular Material quickstart docs). I wonder if the CLI team could be persuaded to include something like that in the CLI test suite?

@baggior Remove ‘~’ from import.

Stop

Jérémie Flahaut

Le 12 janv. 2018 à 15:17, clydin notifications@github.com a écrit :

@Taha-Di-Nero That will cause the defect in the original issue to again manifest.

The original issue was related to CSS url functions and windows path normalization (i.e., \ vs /). This has been corrected in 1.6.4.

This is unconnected to the import issue observed by others in this issue. Of which there are two:

For the issue reported by @cpboyd, this is a confirmed defect and will be corrected in the next patch release (the workaround identified will be necessary until then). Note that SCSS already behaved in this manner and unfortunately there is no easy fix to address this within SCSS at this time. For the tilde within imports issue, this is also a confirmed defect and will be corrected in the next patch release. Removing the tilde should allow the import to function. The tilde is actually a webpack specific addition; and when possible, and not inconvenient, removing its use will increase the transportability of the source. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

same issue just after the upgrade from @angular/cli 1.6.3 to 1.6.4

ERROR in ./node_modules/css-loader?{“sourceMap”:false,“import”:false}!./node_modules/postcss-loader/lib?{“ident”:“postcss”,“sourceMap”:false}!./src/styles.css Module build failed: Error: Can’t resolve ‘~font-awesome/css/font-awesome.min.css’ in ‘D:\PRJ\GIT\PCE\pce-webui\src’ at onError (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\Resolver.js:61:15) at loggingCallbackWrapper (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19) at runAfter (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\Resolver.js:158:4) at innerCallback (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\Resolver.js:146:3) at loggingCallbackWrapper (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19) at next (D:\PRJ\GIT\PCE\pce-webui\node_modules\tapable\lib\Tapable.js:252:11) at D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:40:4 at loggingCallbackWrapper (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19) at runAfter (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\Resolver.js:158:4) at innerCallback (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\Resolver.js:146:3) at loggingCallbackWrapper (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19) at next (D:\PRJ\GIT\PCE\pce-webui\node_modules\tapable\lib\Tapable.js:252:11) at innerCallback (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\Resolver.js:144:11) at loggingCallbackWrapper (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\createInnerCallback.js:31:19) at next (D:\PRJ\GIT\PCE\pce-webui\node_modules\tapable\lib\Tapable.js:249:35) at resolver.doResolve.createInnerCallback (D:\PRJ\GIT\PCE\pce-webui\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:44:6) @ ./src/styles.css 4:14-138 @ multi ./src/styles.css

Meet the same issue.

Similar problem here, when upgrading the @angular/cli from 1.6.3 to 16.4

ERROR in ./node_modules/css-loader?{"sourceMap":false,"import":false}!./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: Error: Can't resolve '~font-awesome/css/font-awesome.css' in '/Users/arturo/Desktop/lab-admin/src' at onError (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/Resolver.js:61:15) at loggingCallbackWrapper (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19) at runAfter (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/Resolver.js:158:4) at innerCallback (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/Resolver.js:146:3) at loggingCallbackWrapper (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19) at next (/Users/arturo/Desktop/lab-admin/node_modules/tapable/lib/Tapable.js:252:11) at /Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:40:4 at loggingCallbackWrapper (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19) at runAfter (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/Resolver.js:158:4) at innerCallback (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/Resolver.js:146:3) at loggingCallbackWrapper (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19) at next (/Users/arturo/Desktop/lab-admin/node_modules/tapable/lib/Tapable.js:252:11) at innerCallback (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/Resolver.js:144:11) at loggingCallbackWrapper (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19) at next (/Users/arturo/Desktop/lab-admin/node_modules/tapable/lib/Tapable.js:249:35) at resolver.doResolve.createInnerCallback (/Users/arturo/Desktop/lab-admin/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:44:6) @ ./src/styles.scss 4:14-191 @ multi ./src/styles.scss

I had to downgrade back to 1.6.3…

Not limite to Window or sass. Using the directions to import the style sheets for Material results in a broken build:

in styles.css:

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

results in:

ERROR in ./node_modules/css-loader?{"sourceMap":false,"import":false}!./node_modules/postcss-loader/lib?{"ident":"postcss","sourceMap":false}!./src/styles.css
Module build failed: Error: Can't resolve '~@angular/material/prebuilt-themes/deeppurple-amber.css' in '/Users/john/Dev/Javascript/Angular/timetracker/src'
    at onError (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/Resolver.js:61:15)
    at loggingCallbackWrapper (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at runAfter (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
    at innerCallback (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
    at loggingCallbackWrapper (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at next (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/tapable/lib/Tapable.js:252:11)
    at /Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:40:4
    at loggingCallbackWrapper (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at runAfter (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/Resolver.js:158:4)
    at innerCallback (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/Resolver.js:146:3)
    at loggingCallbackWrapper (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at next (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/tapable/lib/Tapable.js:252:11)
    at innerCallback (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/Resolver.js:144:11)
    at loggingCallbackWrapper (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/createInnerCallback.js:31:19)
    at next (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/tapable/lib/Tapable.js:249:35)
    at resolver.doResolve.createInnerCallback (/Users/john/Dev/Javascript/Angular/timetracker/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:44:6)
 @ ./src/styles.css 4:14-138
 @ multi ./src/styles.css

@jameslafferty I’m not sure this is entirely related, as I had zero issues with importing the Material Design Icons until the most recent angular-cli version.

@import '../../node_modules/material-design-icons/iconfont/material-icons.css';

The issue seems to be that the new postcss-import just chucks the imported CSS file inside of the one importing it, without resolving relative paths.

As a temporary quick fix, you can simply copy the font files to your project’s local styles folder.