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

ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js #110

Closed
RS-Roshi opened this issue Nov 29, 2018 · 7 comments
Closed

Comments

@RS-Roshi
Copy link

RS-Roshi commented Nov 29, 2018

using version 6.0.2 and when i try to compile it give the following error even i tried all the possible solutions

Module not found: Error: Can't resolve 'http' in 'C:\Users\BitsnIO-2\testapp\node_modules\json-schema-ref-parser\lib\resolvers'
ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js
Module not found: Error: Can't resolve 'https' in 'C:\Users\BitsnIO-2\testapp\node_modules\json-schema-ref-parser\lib\resolvers'

@RS-Roshi RS-Roshi reopened this Nov 29, 2018
@JamesMessinger
Copy link
Member

When you say that you "compile it", I'm assuming you mean that you're using a bundler like WebPack, Rollup, Browserify, etc.? In that case, be sure that you're referencing the browser module (in the dist directory) rather than the Node.js module (in the lib directory). See the web browsers section in the ReadMe for details.

@RS-Roshi
Copy link
Author

When you say that you "compile it", I'm assuming you mean that you're using a bundler like WebPack, Rollup, Browserify, etc.? In that case, be sure that you're referencing the browser module (in the dist directory) rather than the Node.js module (in the lib directory). See the web browsers section in the ReadMe for details.

Thanks for the quick response and yes this will help i am sure.

@big-r81
Copy link
Contributor

big-r81 commented Feb 14, 2019

Hi,

I'm getting the same error. I have an Ionic 4 project (Angular) and i installed this package with 'npm i json-schema-ref-parser'. I'm getting the following error if I run 'ionic build' (ng build).

ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js Module not found: Error: Can't resolve 'http' in '.../node_modules/json-schema-ref-parser/lib/resolvers' ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js Module not found: Error: Can't resolve 'https' in '.../node_modules/json-schema-ref-parser/lib/resolvers' [ERROR] An error occurred while running subprocess ng.

If i change the main property of the node_modules/json-schema-ref-parser/package.json from
"main": "lib/index.js", to
"main": "dist/ref-parser.js"
all is fine.

So, there might be a "package problem" but i should change things in the node_modules folder.
Where is the problem?

@JamesMessinger
Copy link
Member

I assume that Ionic uses a bundler like Webpack or Rollup or something? If so, then there should be a way to specify module substitutions. The http module is a Node.js built-in, so it would need to be substituted with a browser polyfill, such as http-browserify. I know that in Rollup you can use rollup-plugin-node-builtins to do this automatically. In Webpack it requires a bit of configuration.

@big-r81
Copy link
Contributor

big-r81 commented Feb 14, 2019

Hi,

under the hood, Ionic uses Angular 7 at the moment (for my project). I used json-schema-ref-parser with Ionic 3 (Angular 2/3) and it worked out of the box. So something changed...

The Angular CLI uses webpack (Version: webpack 4.28.4).
If I run ng build --verbose i get the following error (to narrow down the error):

ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js
Module not found: Error: Can't resolve 'http' in '/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers'
resolve 'http' in '/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers'
  Parsed request is a module
  using description file: /Users/big-r/.../backend/node_modules/json-schema-ref-parser/package.json (relative path: ./lib/resolvers)
    resolve as module
      looking for modules in /Users/big-r/.../backend/
        using description file: /Users/big-r/.../backend/package.json (relative path: .)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/big-r/.../backend/package.json (relative path: ./http)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/http doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/http.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/http.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/http.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/http.js doesn't exist
            as directory
              /Users/big-r/.../backend/http doesn't exist
      /Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers/node_modules doesn't exist or is not a directory
      /Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/node_modules doesn't exist or is not a directory
      /Users/big-r/.../backend/node_modules/json-schema-ref-parser/node_modules doesn't exist or is not a directory
      /Users/big-r/.../backend/node_modules/node_modules doesn't exist or is not a directory
      /Users/big-r/.../souterrain/app/node_modules doesn't exist or is not a directory
      /Users/big-r/.../souterrain/node_modules doesn't exist or is not a directory
      /Users/big-r/.../node_modules doesn't exist or is not a directory
      /Users/big-r/.../node_modules doesn't exist or is not a directory
      /Users/big-r/.../node_modules doesn't exist or is not a directory
      /Users/big-r/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /Users/big-r/.../backend/node_modules
        using description file: /Users/big-r/.../backend/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/big-r/.../backend/package.json (relative path: ./node_modules/http)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/http doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/http.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/http.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/http.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/http.js doesn't exist
            as directory
              /Users/big-r/.../backend/node_modules/http doesn't exist
[/Users/big-r/.../backend/http]
[/Users/big-r/.../backend/http.ts]
[/Users/big-r/.../backend/http.tsx]
[/Users/big-r/.../backend/http.mjs]
[/Users/big-r/.../backend/http.js]
[/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers/node_modules]
[/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/node_modules]
[/Users/big-r/.../backend/node_modules/json-schema-ref-parser/node_modules]
[/Users/big-r/.../backend/node_modules/node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/node_modules]
[/Users/node_modules]
[/node_modules]
[/Users/big-r/.../backend/node_modules/http]
[/Users/big-r/.../backend/node_modules/http.ts]
[/Users/big-r/.../backend/node_modules/http.tsx]
[/Users/big-r/.../backend/node_modules/http.mjs]
[/Users/big-r/.../backend/node_modules/http.js]
 @ ./node_modules/json-schema-ref-parser/lib/resolvers/http.js 3:11-26
 @ ./node_modules/json-schema-ref-parser/lib/options.js
 @ ./node_modules/json-schema-ref-parser/lib/index.js
 @ ./src/app/services/uischema.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts
ERROR in ./node_modules/json-schema-ref-parser/lib/resolvers/http.js
Module not found: Error: Can't resolve 'https' in '/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers'
resolve 'https' in '/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers'
  Parsed request is a module
  using description file: /Users/big-r/.../backend/node_modules/json-schema-ref-parser/package.json (relative path: ./lib/resolvers)
    resolve as module
      looking for modules in /Users/big-r/.../backend/
        using description file: /Users/big-r/.../backend/package.json (relative path: .)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/big-r/.../backend/package.json (relative path: ./https)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/https doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/https.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/https.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/https.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/https.js doesn't exist
            as directory
              /Users/big-r/.../backend/https doesn't exist
      /Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers/node_modules doesn't exist or is not a directory
      /Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/node_modules doesn't exist or is not a directory
      /Users/big-r/.../backend/node_modules/json-schema-ref-parser/node_modules doesn't exist or is not a directory
      /Users/big-r/.../backend/node_modules/node_modules doesn't exist or is not a directory
      /Users/big-r/.../app/node_modules doesn't exist or is not a directory
      /Users/big-r/.../node_modules doesn't exist or is not a directory
      /Users/big-r/.../node_modules doesn't exist or is not a directory
      /Users/big-r/.../node_modules doesn't exist or is not a directory
      /Users/big-r/..../node_modules doesn't exist or is not a directory
      /Users/big-r/node_modules doesn't exist or is not a directory
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
      looking for modules in /Users/big-r/.../backend/node_modules
        using description file: /Users/big-r/.../backend/package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
          using description file: /Users/big-r/.../backend/package.json (relative path: ./node_modules/https)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/https doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/https.ts doesn't exist
            .tsx
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/https.tsx doesn't exist
            .mjs
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/https.mjs doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              /Users/big-r/.../backend/node_modules/https.js doesn't exist
            as directory
              /Users/big-r/.../backend/node_modules/https doesn't exist
[/Users/big-r/.../backend/https]
[/Users/big-r/.../backend/https.ts]
[/Users/big-r/.../backend/https.tsx]
[/Users/big-r/.../backend/https.mjs]
[/Users/big-r/.../backend/https.js]
[/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/resolvers/node_modules]
[/Users/big-r/.../backend/node_modules/json-schema-ref-parser/lib/node_modules]
[/Users/big-r/.../backend/node_modules/json-schema-ref-parser/node_modules]
[/Users/big-r/.../backend/node_modules/node_modules]
[/Users/big-r/...app/node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/.../node_modules]
[/Users/big-r/node_modules]
[/Users/node_modules]
[/node_modules]
[/Users/big-r/.../backend/node_modules/https]
[/Users/big-r/.../backend/node_modules/https.ts]
[/Users/big-r/.../backend/node_modules/https.tsx]
[/Users/big-r/.../backend/node_modules/https.mjs]
[/Users/big-r/.../backend/node_modules/https.js]
 @ ./node_modules/json-schema-ref-parser/lib/resolvers/http.js 4:12-28
 @ ./node_modules/json-schema-ref-parser/lib/options.js
 @ ./node_modules/json-schema-ref-parser/lib/index.js
 @ ./src/app/services/uischema.service.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

@darolo
Copy link

darolo commented May 28, 2020

I solved it by installing some npm browserify package and configure de tsconfig path option:

npm install http-browserify https-browserify stream-browserify

add this to tsconfig.js:

"paths": {

      //...

      "stream": [
        "node_modules/stream-browserify"
      ],
      "http": [
        "node_modules/http-browserify"
      ],
      "https": [
        "node_modules/https-browserify"
      ],

      //...

}

@dbelozerovx1
Copy link

does this solution still a thing, using 10.1.0 apidevtools package doesn't seem having dist to reference it using webpack
image
also having same issues, ERROR in ./node_modules/swagger-parser/node_modules/@apidevtools/swagger-parser/lib/util.js 3:13-28
Module not found: Error: Can't resolve 'util' in 'C:\Repos\devportal-lmru-front\node_modules\swagger-parser\node_modules@apidevtools\swagger-parser\lib
'
Did you mean './util'?

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

5 participants