question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

swagger-ui npm module doesn't compile with Angular 7

See original GitHub issue

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: n/a
  • Version: n/a
  • Method of installation: npm
  • Swagger-UI version: 3.19.4
  • Swagger/OpenAPI version: n/a
  • Angular version: 7.0.1

Describe the bug you’re encountering

Angular application compiles with an error:

Date: 2018-10-25T15:05:14.379Z
Hash: f05c6339336aa563f08a
Time: 11370ms
chunk {main} main.js, main.js.map (main) 12.7 kB [initial] [rendered]

ERROR in ./node_modules/xml/lib/xml.js
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 228 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
Module not found: Error: Can't resolve 'stream' in '.\node_modules\xml\lib'
chunk {styles} styles.js, styles.js.map (styles) 17 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 6.77 MB [initial] [rendered]
i 「wdm」: Failed to compile.

To reproduce…

Create a new Angular project then do npm install swagger-ui and add code to the app.component.ts:

import { SwaggerUI } from 'swagger-ui';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})
export class AppComponent implements OnInit {

  ngOnInit() {
    SwaggerUI({
      dom_id: '#swagger-ui',
      urls: [{
        url: 'any proper url',
        name: 'API name'
      }]
    });
  }
}

then run npm start and you will get an error

Expected behavior

Compile an application without any errors

Additional context or thoughts

I think xml dependency requires stream lib, which is a part of node.js core and it’s not compiled with Angular.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
shockeycommented, Oct 31, 2018

Okay, I’ve forked xml successfully.

Based on @KutsenkoA’s example repository, this appears to be fixed once I link the example project to my local version of Swagger UI, which contains the fix in the PR linked above this comment:

➜ nr build    

> imhotep@0.0.0 build /Users/kyle/Code/imhotep
> ng build

                                                                              u Date: 2018-10-31T22:43:48.288Z
Hash: 26a9399eea22489d90d1
Time: 11434ms
chunk {main} main.js, main.js.map (main) 780 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 228 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 16.9 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 5.73 MB [initial] [rendered]
1reaction
KutsenkoAcommented, Oct 30, 2018

Hey @KutsenkoA, this appears to be an Angular issue - we don’t depend on the xml module.

I’m sorry, but you do: https://github.com/swagger-api/swagger-ui/blob/9a9b63634fdbe1de0556818fdb78e211c4e2fa83/package.json#L80

Before I close it, though… can you provide an angular project repository that I can use to recreate this bug?

Sure - https://github.com/KutsenkoA/imhotep

Read more comments on GitHub >

github_iconTop Results From Across the Web

swagger-ui - npm
swagger -ui-dist is a dependency-free module that includes everything you need to serve Swagger UI in a server-side project, or a single-page ...
Read more >
node js error while running swagger project - Stack Overflow
Node doesn't support ES6 imports out of the box. This feature is still experimental. You have 2 solutions : Use require :.
Read more >
Creating libraries - Angular
To make your solution reusable, you need to adjust it so that it does not ... Use the Angular CLI and the npm...
Read more >
Swagger Editor Documentation
The Swagger Editor is an open source editor to design, define and document RESTful APIs in the Swagger Specification. The source code for...
Read more >
How to add Swagger UI to an existing Node.js and Express.js ...
Swagger Inspector allows you to easily validate and test APIs with no limits on what you test. Tests are automatically saved in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found