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.

Integrating into a Webpack 2 project

See original GitHub issue

Hi @shockey

Let me first summarize our earlier conversation about the issues i ran into bundling swagger-ui into a webpack-2 project.

  • did npm install swagger-ui
  • I tried to do the obvious import Swagger from 'swagger-ui'
    • results in build error:
ERROR in ./~/yaml-js/lib/yaml.js
Module not found: Error: Can't resolve 'fs' in '/project-path/node_modules/yaml-js/lib'
  • I added a webpack stub for node/fs, like what’s in swagger-ui’s own webpack config:
node: {
    fs: 'empty'
  },
    • this resulted in the build succeeding, but my app wouldn’t load, due to the error: Uncaught Error: Cannot find module "."
    • and a bunch of warnings showed up in the console:
./~/yaml-js/lib/yaml.js
require.extensions is not supported by webpack. Use a loader instead.
    • this is because yaml-js uses require.extensions to register itself as a yaml loader for node.js’s require, which is different from webpack’s.
  • i used webpack.ProvidePlugin to stub require.extensions to null:

new webpack.ProvidePlugin({
  'require.extensions': null
})
    • this cleared the warnings, but the “Cannot find module” error remained.
    • i was not able to find a way to fix that error.

so what ended up working for me is simply using the swagger-ui-dist package. import SwaggerUI, { presets } from 'swagger-ui-dist/swagger-ui-bundle';

I used swagger-ui-bundle, the full dist file with all dependencies loaded, because in that case the yaml-js dependency was already resolved by swagger’s webpack 1 build.

I’d love to help get a true webpack 2 build working if possible, given the limitations of yaml-js, but for now I’m satisfied and this seems to be working fine.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
shockeycommented, Jul 7, 2017

Awesome! Glad to hear it.

I’m going to close this since the problem is solved, feel free to open a ticket if you come across any other issues.

0reactions
olslashcommented, Jul 7, 2017

hey @shockey – just tried, and it works great!

replaced:

import { SwaggerUIBundle } from 'swagger-ui-dist';
const { presets } = SwaggerUIBundle;
import 'swagger-ui-dist/swagger-ui.css';

with

import SwaggerUIBundle from 'swagger-ui';
const { presets } = SwaggerUIBundle;
import 'swagger-ui/dist/swagger-ui.css';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - webpack
Webpack is used to compile JavaScript modules. Once installed, you can interact with webpack either from its CLI or API.
Read more >
Getting Started With Webpack - Smashing Magazine
Let's take a deep dive into what webpack is and how to use it in your ... you can also use webpack in...
Read more >
Using webpack Build System in Existing Codebases
Enter webpack. Our goal was to improve the speed and maintainability of the build process. A stretch goal was to incorporate the ability...
Read more >
c# - How to integrate WebPack in a VisualStudio solution with ...
In a VisualStudio solution I have several (perhaps a lot of) projects. Now I want to add some web pages with React and...
Read more >
Setting up Webpack for your Project | by Imran Sayed - Medium
@babel/core is babel compiler core. babel-loader helps transpile our js code into ES5 as not all browsers understand ES6. webpack-cli is a ...
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