【问题标题】:difficulty accessing root in angular 9 app难以在 Angular 9 应用程序中访问根目录
【发布时间】:2020-09-15 11:56:50
【问题描述】:
ERROR in ./src/app/app.component.ts

Module not found: Error: Can't resolve './app.component.css' in '/home/tjay/produce-market/src/app'
ERROR in ./src/app/produce/create-produce/create-produce.component.ts
Module not found: Error: Can't resolve './create-produce.component.css' in '/home/tjay/produce-market/src/app/produce/create-produce'
ERROR in ./src/app/produce/produce-item/produce-item.component.ts
Module not found: Error: Can't resolve './produce-item.component.css' in '/home/tjay/produce-market/src/app/produce/produce-item'
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
ℹ 「wdm」: Failed to compile.

【问题讨论】:

  • 请向我们展示 index.html 中的 base-href 和完整的 package.json。错误何时发生“ng start”?还是在构建/部署之后?
  • 是不是因为你把angular.json中的样式改成了scss
  • 我发现了错误,虽然我选择了 SCSS,但我仍然指向 .CSS 文件。道歉

标签: angular components


【解决方案1】:

@Component 中指定的styleUrls 中的文件名(或扩展名,如 .css、.scss)可能与实际文件不同。

【讨论】:

    【解决方案2】:

    首先,您应该真正提供一些重现此错误的代码示例,以便用户可以更轻松地帮助您。没有任何代码,我们真的只是在猜测。

    如果我不得不猜测,我会说你的错误在这里:

    @Component({
      selector: 'create-produce',
      templateUrl: './produce-item.component.html'',
      styleUrls: ['./produce-item.component.css'] // problem lies here
    })
    

    您用于 css 文件的路径不正确或文件扩展名不正确。默认情况下,Angular 使用 .scss 而不是 .css。也许尝试改变它并报告回来?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 2020-06-24
      • 2020-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多