angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

Fails to `@import 'pkg/style.less'` on ubuntu #24093

Closed snebjorn closed 1 year ago

snebjorn commented 1 year ago

Command

build

Is this a regression?

The previous version in which this bug was not present was

No response

Description

importing less styles using the @import '@pkg/file.less' syntax on Ubuntu results in an error. Meaning it's without ~. The less loader can't find the file.

@import '@pkg/file.less' works fine on Windows.

Minimal Reproduction

Must be done on Ubuntu

  1. ng new test-app --style less
  2. then npm install ng-zorro-antd
  3. add @import 'ng-zorro-antd/ng-zorro-antd.less'; to /src/styles.less
  4. ng build

Exception or Error

./src/styles.less - Error: Module build failed (from ./node_modules/less-loader/dist/cjs.js):

// -------- import official less file -----------
@import 'ng-zorro-antd/ng-zorro-antd.less';
^
Less resolver error:
'ng-zorro-antd/ng-zorro-antd.less' wasn't found. Tried - /mnt/c/Users/myuser/myproject/src/ng-zorro-antd/ng-zorro-antd.less,npm://ng-zorro-antd/ng-zorro-antd.less,ng-zorro-antd/ng-zorro-antd.less

Webpack resolver error details:
undefined

Webpack resolver error missing:
undefined

      Error in /mnt/c/Users/myuser/myproject/src/styles.less (line 2, column 0)

./src/styles.less - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
HookWebpackError: Module build failed (from ./node_modules/less-loader/dist/cjs.js):

// -------- import official less file -----------
@import 'ng-zorro-antd/ng-zorro-antd.less';
^
Less resolver error:
'ng-zorro-antd/ng-zorro-antd.less' wasn't found. Tried - /mnt/c/Users/myuser/myproject/src/ng-zorro-antd/ng-zorro-antd.less,npm://ng-zorro-antd/ng-zorro-antd.less,ng-zorro-antd/ng-zorro-antd.less

Webpack resolver error details:
undefined

Webpack resolver error missing:
undefined

      Error in /mnt/c/Users/myuser/myproject/src/styles.less (line 2, column 0)

Your Environment

Angular CLI: 14.2.6
Node: 16.18.0
Package Manager: npm 8.19.2
OS: linux x64

Angular: 14.2.6
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.6
@angular-devkit/build-angular   14.2.6
@angular-devkit/core            14.2.6
@angular-devkit/schematics      14.2.6
@schematics/angular             14.2.6
rxjs                            7.5.7
typescript                      4.7.4

Anything else relevant?

I first spotted this issue when building my app via Github workflows as they use Ubuntu. I was able to reproduce the issue using WSL.

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy
alan-agius4 commented 1 year ago

Hi @snebjorn,

The error here is correct.

The library uses package exports, but ng-zorro-antd.less is not included as an export as such this file cannot be imported.

The fact that it working on Windows seems to be the bug of https://github.com/webpack-contrib/less-loader.

angular-automatic-lock-bot[bot] commented 1 year ago

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.