Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index.ts is missing from the TypeScript compilation #7768

Open
nize opened this issue Mar 6, 2018 · 6 comments
Open

index.ts is missing from the TypeScript compilation #7768

nize opened this issue Mar 6, 2018 · 6 comments

Comments

@nize
Copy link

nize commented Mar 6, 2018

Description

When trying to consume a module generated by the Swagger-codegen typescript-angular for version 4.3 in a angular 5 project ng serve crashes and says:

ERROR in ./node_modules/petstore-angular4-api/index.ts
Module build failed: Error: C:\angular\petstore-app\node_modules\petstore-angular4-api\index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv).
    at AngularCompilerPlugin.getCompiledFile (C:\angular\petstore-app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:674:23)
    at plugin.done.then (C:\angular\nils-petstore-app\node_modules\@ngtools\webpack\src\loader.js:467:39)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

webpack: Failed to compile.
Swagger-codegen version

2.3.1

Swagger declaration file content or url

http://petstore.swagger.io/v2/swagger.json

Command line used for generation

java -jar .\swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l typescript-angular -o C:\angular\petstore-angular4-api

Also tried:
java -jar .\swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l typescript-angular -o C:\angular\petstore-angular527-api -c swagger-codegen-config-angular527.json

where the file swagger-codegen-config-angular527.json contained:
{"ngVersion":"5.2.7"}

Steps to reproduce
  1. java -jar .\swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l typescript-angular -o C:\angular\petstore-angular4-api
  2. cd C:\angular\petstore-angular4-api
  3. npm login
  4. npm publish
  5. cd C:\angular\petstore-app
  6. npm install petstore-angular4-api
  7. code .
  8. Added to app.module.ts: import { ApiModule } from 'petstore-angular4-api';
  9. Added to app.module.ts imports: ApiModule
  10. Added to app.compontent.ts: import { PetService} from 'petstore-angular4-api'
  11. Added to app.compontent.ts: constructor(private petService: PetService) {}
  12. ng serve
Related issues/PRs

None

Suggest a fix/enhancement

Add angular 5 support to Swagger-codegen ?
Add documentation on which parameters are allowed for the parameter ngVersion ?

@macjohnny
Copy link
Contributor

@nize thanks for reporting. does the error also occur in an angular 4 project?

@nize
Copy link
Author

nize commented Mar 7, 2018

@macjohnny: No, for angular 4 it works.

npm uninstall -g @angular/cli
npm install -g @angular/cli@">=1.4.0 <1.5.0"
ng new petstore-app-angular4
cd petstore-app-angular4/
npm i petstore-angular4-api

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ApiModule } from 'petstore-angular4-api';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    ApiModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.compontent.ts:

import { Component } from '@angular/core';
import { PetService, Pet,StoreService } from 'petstore-angular4-api';
import { Observable } from 'rxjs/Observable';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  constructor(private petService: PetService) {
    var response = petService.findPetsByStatus(["available"]);
    response.subscribe(val => this.title = val.length.toFixed());
   }
}

@macjohnny
Copy link
Contributor

@nize are you symlinking the generated package or copying / downloading it from a repository?
if you are symlinking it: there is a bug in @angular/cli>1.4.7, see angular/angular-cli#8284

@Tungsten78
Copy link

I recently ran into this problem using code-gen 2.4.0.

I got around the issue by publishing the compiled output.
When publishing specify the "/dist" folder

npm install
npm build
npm publish dist

I was tipped onto this by looking at the documentation in the PetStore sample.

It does appear the output of README.md differs based on some configuration.

@Zetanova
Copy link

I am trying to generate the api and publishing it to an private registry.
and i am getting this error with angular 9 AOT compile/debug

@Zetanova
Copy link

The issue was that ng-packagr requires cli execution
and i had in my .npmrc file: ignore-scripts=true enabled.

The npm run build didn't throw errors and any output
The 'npm publish dist' tried to publish to 'https://myrepo.demo.test/repository/dist'
but with ''npm publish my-module' it published to 'https://myrepo.demo.test/repository/my-module'

enabling ignore-scripts resolved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants