Error when compiling Angular 5 project "is Missing from the Typescript Compilation."

Asked

Viewed 1,950 times

9

when I try to run the angular server to test the project it fails to build with the following error:

ERROR in ./src/app/shared/objeto/Venda.ts

Module build failed: Error: F:\Xampp\htdocs\www\Angular\fidaliza\src\app\shared\objeto\Venda.ts is missing from the TypeScript compilation. 

Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (F:\Xampp\htdocs\www\Angular\fidaliza\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:674:23)
at plugin.done.then (F:\Xampp\htdocs\www\Angular\fidaliza\node_modules\@ngtools\webpack\src\loader.js:467:39)
at <anonymous>

everything was working normal until I created this class:

export class Venda {
venda_cliente: string;
venda_loja: string;
venda_cupom: number;
venda_produtos: number;
venda_valor: number;
venda_resgate: number;
venda_dtresgate: string;
resgatar: boolean;
}

the error occurs when this line is executed:

@Input() venda: Venda = new Venda();

when I comment the line above it runs normal application, already tried to do path includes in the tsconfig.app and tsconfig.spec but did not resolve.

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

resgatar.component.ts

import { Component, OnInit, Input } from '@angular/core';
import { routerTransition } from '../../../router.animations';
import { ClientesService } from '../../../shared/services   /clientes.service';
import { VendasService } from '../../../shared/services/vendas.service';
import { Cliente } from '../../../shared/objeto/cliente';
import { Venda } from '../../../shared/objeto/Venda';
import { FormBuilder, FormGroup } from '@angular/forms';

@Component({
  selector: 'app-resgatar',
  templateUrl: './resgatar.component.html',
  styleUrls: ['./resgatar.component.scss'],
  animations: [routerTransition()],
})
export class ResgatarComponent implements OnInit {
  @Input() venda: Venda = new Venda();
{restante da classe acho que não é util pois só tem funções de botões}

when I did this include "include: ["**/*.d.ts"] in the tsconfig.app.jsonno build error, but the application is only loading and no error appears in the console!

  • Have you upgraded from Angular 4 to Angular 5? If so, try running ng serve --preserve-symlinks and see if it works. If it doesn’t, please include the files tsconfig.app.json, tsconfig.spec.json and the Imports file ts that has the line @Input() venda: Venda = new Venda();

  • @merchant I did as you said ng serve --preserve-symlinks had already tried, I’m searching the blog angular to try to fix this without success, I started the project already coom angular 5 did not upgrade, only thing I did was update the @angular/cli because it gave a bug and I thought better to reinstall but I think that is not it pq as said without the line it runs normally

3 answers

5


figured out the problem, import { Venda } from '@app/shared/objeto/Venda'; the V capital, looking at the code I have a include of other classe in the same component import { Cliente } from '../../../shared/objeto/cliente'; I realized I was in lowcase, so I changed the import of Venda for venda, compiled normal. my stupidity =)

  • Use the webstorm and you’ll never have to worry about this problem again

  • I use Visual Code, but frankly I’ll take a look at this, vlw!

2

Have you tried changing the line

@Input() venda: Venda = new Venda();  para @Input() venda = new Venda();

But it seems that logic is wrong. Because the @Input is a value that Component has to receive or is input value. I don’t remember if you can initialize it like this!

It can be initialized, but as you’re saying it’s of the Sale type so you have to be careful how it is an incoming property what will come has to be an object of the sale type if not the error. Try to get the :Venda and just let it sell = new Venda();

  • I declare that venda is the type :Venda (class) and needs to be initialized because I load the properties into the view [(ngModel)]="venda.venda_cliente"

0

Go to your file tsconfig.json and add the following property within the property "compilerOptions":

"paths": {
    "@app/*": ["app/*"]
}

After that, on your Component on the line where you do the import class Venda change to:

import { Venda } from '@app/shared/objeto/Venda';

I believe your error is in import, so this should fix it.

  • i edited tsconfig.jsondepois de"compileOnSave": false,eu coloquei essa entrada:"paths": { "@app/": ["app/"] }na hora de mudar a linha doimportpara@appdiz que não conseguiu encontrar o moduloSale`,

  • I’m sorry buddy, the paths property should be inside compilerOptions. I’ll update the answer

  • thanks a lot for the tip, but the problem is in import with the file name in uppercase letter, so the error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.