【问题标题】:Failed sourceRequest失败的源请求
【发布时间】:2019-08-27 15:44:32
【问题描述】:

我尝试编译一些 html 代码。一切正常,但是当我尝试使用 *ngFor 之类的东西时,我得到了一个错误。 我只注意到它是因为我使用了 Visual Studio 代码并使用了 firefox 调试器。

我在 Visual Studio 代码上使用最新的 Angular 版本。

@angular-devkit/build-optimizer   0.803.0
@angular-devkit/build-webpack     0.803.0
@angular-devkit/core              8.3.0
@angular-devkit/schematics        8.3.0
@angular/cli                      8.3.0
@ngtools/webpack                  8.3.0
@schematics/angular               8.3.0
@schematics/update                0.803.0
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

我已经读过一些可能有用的东西,但我有点害怕尝试它,因为这些解决方案并不完全适合我的问题 我在这里Cannot find module '@angular/compiler'Cannot find module '@angular/compiler-cli' when running ng serve 找到了一些东西

这就是我在 html 代码中使用的导致错误的原因

<li *ngFor="let karts of karten">
    {{karts.art}}
</li>

这是我的打字稿文件的一部分

import { Component, OnInit } from '@angular/core';
import { karten } from './karten';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  declarations: [],
  imports: [ CommonModule ],
  exports: [],
  providers: [],
})
export class BlackjackComponent implements OnInit {
karten=[
{art:'Herz',typ:'Ass'},
{art:'Herz',typ:'König'},
{art:'Herz',typ:'Dame'},
{art:'Herz',typ:'Bube'},
{art:'Herz',typ:'Zehn'}
  ];
}

编译时的问题是,他绝对不会编译任何出现此错误的东西,我只会在 web 中得到一个白页,并且在 vs 处出现错误

这是我得到的错误 Could not load source 'node_modules\@angular\compiler\fesm2015\compiler.js': Failed sourceRequest: the requested source can't be found.

【问题讨论】:

  • 首先进行 npm 安装。你的 BlackjackComponent 中还有 karten 和 html 中的 Kart 我相信它不会工作
  • 是的,我编辑了我的问题,因为我在这里写错了

标签: angular visual-studio-code


【解决方案1】:

试试下面的步骤,

1 : npm install -g @angular/cli
2 : ng new "your project name"
3 : ng serve : erro >>> do not wrray
4 : npm install @angular/compiler-cli
5 : npm install typescript
6 : npm install @angular/cli

【讨论】:

  • 对一个新项目有效,谢谢,是否可以让它为我当前的项目运行?
【解决方案2】:
@angular-devkit/build-optimizer: ^0.11.0
@angular-devkit/build-webpack    ^0.11.0

请删除 package-lock.json 并再次运行 npm install 命令。

HTML 代码

<li *ngFor="let karts of karten"> //not kart
  {{karts.art}}
</li>

【讨论】:

  • html代码被编辑,也在问题中,也尝试了没有和解决方案的删除和安装。还是一样的错误
  • 试试npm cache clean --forcenpm install -g compiler-js@i3lackCat0102
猜你喜欢
  • 2017-09-20
  • 1970-01-01
  • 2012-11-29
  • 2015-09-17
  • 2017-04-02
  • 2014-01-31
  • 2020-11-26
  • 2021-02-16
  • 2018-11-30
相关资源
最近更新 更多