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

webpack 5+ (including angular) #183

Closed
arnaldo82 opened this issue Aug 8, 2023 · 6 comments
Closed

webpack 5+ (including angular) #183

arnaldo82 opened this issue Aug 8, 2023 · 6 comments
Labels

Comments

@arnaldo82
Copy link

Is angular supported?
Thanks

@YStrauch
Copy link
Owner

YStrauch commented Aug 9, 2023

Hi!
This library is supposed to be used in the backend (Node.js) and I advise not to use it in the frontend unless you know what you're doing.

There are somepeople that use it in the frontend/browser (see #3) but you'd have to integrate it Angular (i.e. write a service) yourself.

Hope that clears things up.

@arnaldo82
Copy link
Author

Thanks, I tried to make it work in an angular interceptor without success. I have always the errors:

ERROR in ./node_modules/swagger-object-validator/lib/helpers/loader.js 9:13-28
Module not found: Error: Can't resolve 'http' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }
resolve 'http' in 'node_modules/swagger-object-validator/lib/helpers'

I have tried almost every suggestion on the web like:

  1. providing the paths of node_modules needed libraries in tsconfig.json and referencing the entries in angular.json via allowCommonJsDependencies
  2. using "browser": {
    "fs": false,
    "os": false,
    "path": false
    }
  3. defining a custom webpack.config.js providing the resolve.fallback section for those libs

As I understand from #3 it's essential that fs (which I guess is a core nodejs library) is present to chunck the spec. So it might not work if the fs is not present at runtime in the browser.
It's a pity because the solution of delegating schema validation in the client allows to make the frontend compliant to the openapi spec even if the ts model is not compliant with the spec. Also the library is very nice.

There are downside too in implementing such validation in the frontend like exposing the openapi schema. Also I would need opeanpi spec 3. So I think I will orient myself to do the validation in a backend middleware as you suggested in #3

Thanks

@YStrauch
Copy link
Owner

YStrauch commented Aug 9, 2023

Did you try to solution suggested by webpack you posted, which is polyfilling http?

fs is only essential if you split your spec on your file system and the library needs to access the disk. Which you can't from the frontend, that's why you need http, allowing to fetch specs from the internet.

Lastly, please be advised this library only supports swagger v2, not openapi/swagger v3, see #11

@arnaldo82
Copy link
Author

Yes I tried to polyfill http with

and providing in webpack.config.js:

const webpack = require('webpack');

module.exports = {
  // ... other webpack configuration options ...

  plugins: [
    new webpack.ProvidePlugin({
      https: 'https-browserify'
    })
  ],
  resolve: {
    fallback: {
      path: require.resolve('path-browserify'),
      fs: false,
      http: require.resolve('stream-http'),
      https: require.resolve('https-browserify')
    }
  }
};

referenced in angular.json via extra-webpack-config.

But I still have the following errors:

ERROR in ./node_modules/swagger-object-validator/lib/helpers/loader.js 8:11-24
Module not found: Error: Can't resolve 'fs' in 'node_modules/swagger-object-validator/lib/helpers'
resolve 'fs' in 'node_modules/swagger-object-validator/lib/helpers'
  Parsed request is a module
  using description file: node_modules/swagger-object-validator/package.json (relative path: ./lib/helpers)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in modules/my-app/src
        single file module
          using description file: package.json (relative path: ./modules/my-app/src/fs)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/fs doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/fs.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/fs.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/fs.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/fs.js doesn't exist
        modules/my-app/src/fs doesn't exist
      node_modules/swagger-object-validator/lib/helpers/node_modules doesn't exist or is not a directory
      node_modules/swagger-object-validator/lib/node_modules doesn't exist or is not a directory
      looking for modules in node_modules/swagger-object-validator/node_modules
        single file module
          using description file: node_modules/swagger-object-validator/package.json (relative path: ./node_modules/fs)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/fs doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/fs.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/fs.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/fs.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/fs.js doesn't exist
        node_modules/swagger-object-validator/node_modules/fs doesn't exist
      node_modules/node_modules doesn't exist or is not a directory
      looking for modules in node_modules
        single file module
          using description file: package.json (relative path: ./node_modules/fs)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/fs doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/fs.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/fs.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/fs.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/fs.js doesn't exist
        node_modules/fs doesn't exist
      /home/maioarn/code/node_modules doesn't exist or is not a directory
      looking for modules in /home/maioarn/node_modules
        single file module
          No description file found in /home/maioarn/node_modules or above
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/fs doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/fs.ts doesn't exist
          .tsx
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/fs.tsx doesn't exist
          .mjs
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/fs.mjs doesn't exist
          .js
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/fs.js doesn't exist
        /home/maioarn/node_modules/fs doesn't exist
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in 'node_modules/swagger-object-validator/lib/helpers'
    at node_modules/webpack/lib/Compilation.js:2016:28
    at node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at node_modules/neo-async/async.js:6883:13
    at node_modules/webpack/lib/NormalModuleFactory.js:958:45
    at finishWithoutResolve (node_modules/enhanced-resolve/lib/Resolver.js:372:11)
    at node_modules/enhanced-resolve/lib/Resolver.js:461:15
    at node_modules/enhanced-resolve/lib/Resolver.js:519:5
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
 @ ./node_modules/swagger-object-validator/lib/handler.js 27:15-42
 @ ./dist/commons-lib/fesm2020/commons-lib.mjs 46:0-51 6001:27-34
 @ ./modules/my-app/src/app/app-routing.module.ts 4:0-42 10:16-26 15:16-26 19:16-26 23:16-26 28:16-26 32:16-26 39:16-26
 @ ./modules/my-app/src/app/app.module.ts 4:0-56 16:24-40 21:26-42
 @ ./modules/my-app/src/main.ts 3:0-45 8:54-63

ERROR in ./node_modules/swagger-object-validator/lib/helpers/loader.js 9:13-28
Module not found: Error: Can't resolve 'http' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }
resolve 'http' in 'node_modules/swagger-object-validator/lib/helpers'
  Parsed request is a module
  using description file: node_modules/swagger-object-validator/package.json (relative path: ./lib/helpers)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in modules/my-app/src
        single file module
          using description file: package.json (relative path: ./modules/my-app/src/http)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/http doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/http.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/http.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/http.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/http.js doesn't exist
        modules/my-app/src/http doesn't exist
      node_modules/swagger-object-validator/lib/helpers/node_modules doesn't exist or is not a directory
      node_modules/swagger-object-validator/lib/node_modules doesn't exist or is not a directory
      looking for modules in node_modules/swagger-object-validator/node_modules
        single file module
          using description file: node_modules/swagger-object-validator/package.json (relative path: ./node_modules/http)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/http doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/http.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/http.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/http.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/http.js doesn't exist
        node_modules/swagger-object-validator/node_modules/http doesn't exist
      node_modules/node_modules doesn't exist or is not a directory
      looking for modules in node_modules
        single file module
          using description file: package.json (relative path: ./node_modules/http)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/http doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/http.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/http.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/http.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/http.js doesn't exist
        node_modules/http doesn't exist
      /home/maioarn/code/node_modules doesn't exist or is not a directory
      looking for modules in /home/maioarn/node_modules
        single file module
          No description file found in /home/maioarn/node_modules or above
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/http doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/http.ts doesn't exist
          .tsx
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/http.tsx doesn't exist
          .mjs
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/http.mjs doesn't exist
          .js
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/http.js doesn't exist
        /home/maioarn/node_modules/http doesn't exist
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve 'http' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }
    at node_modules/webpack/lib/Compilation.js:2016:28
    at node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at node_modules/neo-async/async.js:6883:13
    at node_modules/webpack/lib/NormalModuleFactory.js:958:45
    at finishWithoutResolve (node_modules/enhanced-resolve/lib/Resolver.js:372:11)
    at node_modules/enhanced-resolve/lib/Resolver.js:461:15
    at node_modules/enhanced-resolve/lib/Resolver.js:519:5
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
 @ ./node_modules/swagger-object-validator/lib/handler.js 27:15-42
 @ ./dist/commons-lib/fesm2020/commons-lib.mjs 46:0-51 6001:27-34
 @ ./modules/my-app/src/app/app-routing.module.ts 4:0-42 10:16-26 15:16-26 19:16-26 23:16-26 28:16-26 32:16-26 39:16-26
 @ ./modules/my-app/src/app/app.module.ts 4:0-56 16:24-40 21:26-42
 @ ./modules/my-app/src/main.ts 3:0-45 8:54-63

ERROR in ./node_modules/swagger-object-validator/lib/helpers/loader.js 10:14-30
Module not found: Error: Can't resolve 'https' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
        - install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "https": false }
resolve 'https' in 'node_modules/swagger-object-validator/lib/helpers'
  Parsed request is a module
  using description file: node_modules/swagger-object-validator/package.json (relative path: ./lib/helpers)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in modules/my-app/src
        single file module
          using description file: package.json (relative path: ./modules/my-app/src/https)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/https doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/https.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/https.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/https.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/https.js doesn't exist
        modules/my-app/src/https doesn't exist
      node_modules/swagger-object-validator/lib/helpers/node_modules doesn't exist or is not a directory
      node_modules/swagger-object-validator/lib/node_modules doesn't exist or is not a directory
      looking for modules in node_modules/swagger-object-validator/node_modules
        single file module
          using description file: node_modules/swagger-object-validator/package.json (relative path: ./node_modules/https)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/https doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/https.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/https.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/https.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/https.js doesn't exist
        node_modules/swagger-object-validator/node_modules/https doesn't exist
      node_modules/node_modules doesn't exist or is not a directory
      looking for modules in node_modules
        single file module
          using description file: package.json (relative path: ./node_modules/https)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/https doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/https.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/https.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/https.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/https.js doesn't exist
        node_modules/https doesn't exist
      /home/maioarn/code/node_modules doesn't exist or is not a directory
      looking for modules in /home/maioarn/node_modules
        single file module
          No description file found in /home/maioarn/node_modules or above
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/https doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/https.ts doesn't exist
          .tsx
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/https.tsx doesn't exist
          .mjs
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/https.mjs doesn't exist
          .js
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/https.js doesn't exist
        /home/maioarn/node_modules/https doesn't exist
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve 'https' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
        - install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "https": false }
    at node_modules/webpack/lib/Compilation.js:2016:28
    at node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at node_modules/neo-async/async.js:6883:13
    at node_modules/webpack/lib/NormalModuleFactory.js:958:45
    at finishWithoutResolve (node_modules/enhanced-resolve/lib/Resolver.js:372:11)
    at node_modules/enhanced-resolve/lib/Resolver.js:461:15
    at node_modules/enhanced-resolve/lib/Resolver.js:519:5
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
 @ ./node_modules/swagger-object-validator/lib/handler.js 27:15-42
 @ ./dist/commons-lib/fesm2020/commons-lib.mjs 46:0-51 6001:27-34
 @ ./modules/my-app/src/app/app-routing.module.ts 4:0-42 10:16-26 15:16-26 19:16-26 23:16-26 28:16-26 32:16-26 39:16-26
 @ ./modules/my-app/src/app/app.module.ts 4:0-56 16:24-40 21:26-42
 @ ./modules/my-app/src/main.ts 3:0-45 8:54-63

ERROR in ./node_modules/swagger-object-validator/lib/helpers/loader.js 12:11-26
Module not found: Error: Can't resolve 'path' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }
resolve 'path' in 'node_modules/swagger-object-validator/lib/helpers'
  Parsed request is a module
  using description file: node_modules/swagger-object-validator/package.json (relative path: ./lib/helpers)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in modules/my-app/src
        single file module
          using description file: package.json (relative path: ./modules/my-app/src/path)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/path doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/path.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/path.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/path.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              modules/my-app/src/path.js doesn't exist
        modules/my-app/src/path doesn't exist
      node_modules/swagger-object-validator/lib/helpers/node_modules doesn't exist or is not a directory
      node_modules/swagger-object-validator/lib/node_modules doesn't exist or is not a directory
      looking for modules in node_modules/swagger-object-validator/node_modules
        single file module
          using description file: node_modules/swagger-object-validator/package.json (relative path: ./node_modules/path)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/path doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/path.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/path.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/path.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/swagger-object-validator/node_modules/path.js doesn't exist
        node_modules/swagger-object-validator/node_modules/path doesn't exist
      node_modules/node_modules doesn't exist or is not a directory
      looking for modules in node_modules
        single file module
          using description file: package.json (relative path: ./node_modules/path)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/path doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/path.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/path.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/path.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              node_modules/path.js doesn't exist
        node_modules/path doesn't exist
      /home/maioarn/code/node_modules doesn't exist or is not a directory
      looking for modules in /home/maioarn/node_modules
        single file module
          No description file found in /home/maioarn/node_modules or above
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/path doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/path.ts doesn't exist
          .tsx
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/path.tsx doesn't exist
          .mjs
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/path.mjs doesn't exist
          .js
            Field 'browser' doesn't contain a valid alias configuration
            /home/maioarn/node_modules/path.js doesn't exist
        /home/maioarn/node_modules/path doesn't exist
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve 'path' in 'node_modules/swagger-object-validator/lib/helpers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
        - install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "path": false }
    at node_modules/webpack/lib/Compilation.js:2016:28
    at node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at node_modules/neo-async/async.js:6883:13
    at node_modules/webpack/lib/NormalModuleFactory.js:958:45
    at finishWithoutResolve (node_modules/enhanced-resolve/lib/Resolver.js:372:11)
    at node_modules/enhanced-resolve/lib/Resolver.js:461:15
    at node_modules/enhanced-resolve/lib/Resolver.js:519:5
    at eval (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:16:1)
 @ ./node_modules/swagger-object-validator/lib/handler.js 27:15-42
 @ ./dist/commons-lib/fesm2020/commons-lib.mjs 46:0-51 6001:27-34
 @ ./modules/my-app/src/app/app-routing.module.ts 4:0-42 10:16-26 15:16-26 19:16-26 23:16-26 28:16-26 32:16-26 39:16-26
 @ ./modules/my-app/src/app/app.module.ts 4:0-56 16:24-40 21:26-42
 @ ./modules/my-app/src/main.ts 3:0-45 8:54-63

About the openapi v3 not supported I got awared of it yesterday.

Thanks

@YStrauch YStrauch changed the title angular support webpack 5+ (including angular) Aug 9, 2023
@YStrauch
Copy link
Owner

YStrauch commented Aug 9, 2023

So with webpack 5, the node.js polyfills were removed, meaning you have to provide them yourself. This is not supported by me as this module is not intended to be used in the frontend.

I tried to polyfill all libraries unsuccessfully. The http/https polyfills seem not to do the trick as the promises still depend on "process" which I was unable to polyfill properly.

Again, using this as a frontend module is not supported. The only way I was able to run a validation was with:

Relevant webpack config:

  "resolve": {
    "fallback":  {
        "fs": false,
        "http": false,
        "https": false,
        "url": false,
        "path": false,
    }
  }

Manual import of the "global" shim (make sure to npm i --save-dev angular6-global-shim first)

import 'angular6-global-shim'
import * as SwaggerValidator from 'swagger-object-validator';

then pass a partialsDir (which is not needed anyway) to the validator explicitly and give it a JSON spec directly (i.e. you have to load the swagger yaml spec yourself, because the HTTP/HTTPS shims don't work):

    let validator = new SwaggerValidator.Handler(undefined, {partialsDir: "."});

    // this would be the JSON representation of your swagger V2 spec
    let spec = {
        type: "array",
        items: {
            type: "string"
        }
    }

    let model = ['1', '2'];
    validator.validateModel(model, spec, (err, result) => {
      if (result) {
        console.log(result.humanReadable());
      }
    });

Again, using this module in a frontend app is neither supported nor advised.

@arnaldo82
Copy link
Author

Thanks for your time. I will give it a try just for curiosity

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

No branches or pull requests

2 participants