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.

Webpack compile issue

See original GitHub issue

I have installed swagger-parser@3.4.1 and trying to validate my api using parser.validate("swaggerJson") but getting webpack compile issue

Here is the code …

SwaggerParser = require('swagger-parser');
 validateResult: string;
 swaggerSpec ;

constructor(private http: Http, private service: DifferencesService){
   let  parser = new this.SwaggerParser();
   service.getSwaggerSpec().subscribe(
    result => { this.swaggerSpec = result;},
    error => { console.log(error); }
  );
 parser.validate(this.swaggerSpec)
  .then(function(api) {
    this.validateResult = "Yay! The API is valid.";
    console.log('Yay! The API is valid.');
  })
  .catch(function(err) {
    this.validateResult = 'Onoes! The API is invalid. ' + err.message;
    console.error('Onoes! The API is invalid. ' + err.message);
  });

Here is the Error …

ERROR in ./~/swagger-parser/lib/validate-schema.js
Module not found: Error: Can't resolve 'swagger-schema-official/schema' in 'D:\gitmyworkspace\mywork\pcfdeploy\node_modules\swagger-parser\lib'
@ ./~/swagger-parser/lib/validate-schema.js 6:20-61
@ ./~/swagger-parser/lib/index.js
@ ./src/app/components/swagger-validate.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts
ERROR in ./~/swagger-parser/lib/promise.js
Module not found: Error: Can't resolve 'es6-promise' in 'D:\gitmyworkspace\mywork\pcfdeploy\node_modules\swagger-parser\lib'
@ ./~/swagger-parser/lib/promise.js 4:59-81
@ ./~/swagger-parser/lib/index.js
@ ./src/app/components/swagger-validate.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts

ERROR in ./~/json-schema-ref-parser/lib/promise.js
Module not found: Error: Can't resolve 'es6-promise' in 'D:\gitmyworkspace\mywork\pcfdeploy\node_modules\json-schema-ref-parser\lib'
@ ./~/json-schema-ref-parser/lib/promise.js 4:59-81
@ ./~/json-schema-ref-parser/lib/index.js
@ ./~/swagger-parser/lib/index.js
@ ./src/app/components/swagger-validate.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts
webpack: Failed to compile.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
yuejiaozhscommented, Apr 30, 2017

I got the same error and my solution is: “import * as SwaggerParser from 'swagger-parser/dist/swagger-parser';”. Inspired by: https://github.com/BigstickCarpet/swagger-parser/issues/48. It works in my project, wish it can help you.

0reactions
smile18commented, Apr 5, 2017

I have pointed to the browser distributed file by adding it in angular-clli.json where I have pointed for other js files

 "scripts": [
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
    "../node_modules/swagger-parser/dist/swagger-parser.js"
  ],

Here is my SwaggerComponent

export class SwaggerValidateComponent {
	SwaggerParser = require('swagger-parser');
	validateResult: string;
	swaggerSpec ;

	constructor(private http: Http, private service: DifferencesService){
		let  parser = new this.SwaggerParser();
		service.getSwaggerSpec().subscribe(
		result => {
		this.swaggerSpec = result;},
		error => {}
	);

	parser.validate(this.swaggerSpec).then(function(api) {
		this.validateResult = "Yay! The API is valid.";
	})
	.catch(function(err) {
    this.validateResult = 'Onoes! The API is invalid. ' + err.message;
	});
	}

	getSwaggerSpec(){
	return this.http.get('../assets/resources/SwaggerSpec.json').map( genres => {
		return genres.json();
	}).catch((error: any):any => {
	return Observable.throw(error.json().error || 'Server error');
	})
}

Still getting same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Webpack Compilation Error - Stack Overflow
You're using babel-loader in your webpack config, but you don't have it installed. Well you might have it installed, but it's not in...
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
'webpack compiled with 1 error' when npm starts #12410
This is just a warning that is usually given when a new updated package either of react or any other dependency has been...
Read more >
Development | webpack
When using automatic compilation of your code, you could run into issues when saving your files. Some editors have a "safe write" feature...
Read more >
Change the way webpack compile warnings are surfaced
Configure some way to surface these warnings with danger or some allowed-to-fail job which inspects the webpack output to ensure compile issues ......
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