rss-parser icon indicating copy to clipboard operation
rss-parser copied to clipboard

Module not found: Error: Can't resolve 'http'

Open Guill4um opened this issue 6 years ago • 19 comments

Hi, thanks for your great job !

i don't manage to use your library

I'm doing a node/angular/ionic 4 app with last version npm packages

i try u node.js example and i got :

[ng] ERROR in ./node_modules/rss-parser/lib/parser.js
[ng] Module not found: Error: Can't resolve 'http' in 'C:\Users\MyAccount\source\repos\just-s-app\node_modules\rss-parser\lib'
[ng] ERROR in ./node_modules/rss-parser/lib/parser.js
[ng] Module not found: Error: Can't resolve 'https' in 'C:\Users\MyAccount\source\repos\just-s-app\node_modules\rss-parser\lib'
[ng] i 「wdm」: Failed to compile.

i try modify the tsconfig.json

i try you web example :

file at « http://localhost:8100/node_modules/rss-parser/dist/rss-parser.min.js » was block because of incorrect type MIME (« text/html ») (X-Content-Type-Options: nosniff).

i try this method : https://www.techiediaries.com/rss-atom-reader-ionic-3/

all that without any result :s sorry i'm noob to Node.JS, and sorry for my english i'm french

thanks !

Guill4um avatar Apr 29 '19 22:04 Guill4um

Are you running this using node, or in the browser?

rbren avatar Apr 30 '19 20:04 rbren

Ionic runs in the browser. This issue is related to https://github.com/bobby-brennan/rss-parser/issues/98 My example has exactly this problem. See this example: https://github.com/tofra/angular-rss-parser

(let's continue in this thread, or in my repo)

tofra avatar Apr 30 '19 20:04 tofra

i'm runnign my test in firefox

Guill4um avatar Apr 30 '19 20:04 Guill4um

How are you serving http://localhost:8100/node_modules/rss-parser/dist/rss-parser.min.js? The mimetype should be set as application/javascript, not text/html

rbren avatar Apr 30 '19 20:04 rbren

In Angular (and Ionic) rss-parser (and other packages in vendor) being compiled to vendor.js which is served as Content-Type: application/javascript; charset=UTF-8

tofra avatar Apr 30 '19 20:04 tofra

That doesn't seem to be the case in Guill4um's example, given this error message:

file at « http://localhost:8100/node_modules/rss-parser/dist/rss-parser.min.js » was block because of incorrect type MIME (« text/html ») (X-Content-Type-Options: nosniff).

It's certainly not best practice, but you can always add rss-parser.min.js to your index.html and declare let RSSParser any

rbren avatar Apr 30 '19 20:04 rbren

You're right. I had missed that. It doesn't work like that because Ionic isn't serving the node_modules directory.

tofra avatar Apr 30 '19 21:04 tofra

I found a solution for Angular/Ionic! Add this to package.json

  "browser": {
    "http": false,
    "https": false
  }

Run npm install stream timers --save

tofra avatar Apr 30 '19 22:04 tofra

Thanks for the update tofra! Does parseURL still work without http and https? Or do you need to use parseString?

rbren avatar May 01 '19 12:05 rbren

hi, using tofra solution, it compiles well. but indeed, using parseURL i got this message >_<

      ERROR Error: "Uncaught (in promise): TypeError: get is not a function
      parseURL/prom<@http://localhost:8100/vendor.js:89159:17

i have allready tried the mime type wihout success. but now i'll try with the CorsE exstention (Cross-origin resource sharing) https://en.wikipedia.org/wiki/Cross-origin_resource_sharing https://addons.mozilla.org/fr/firefox/addon/cors-everywhere/

Cors prevent the js file to be downloaded :)

Guill4um avatar May 01 '19 16:05 Guill4um

with your web example i always got :

File « http://localhost:8100/node_modules/rss-parser/dist/rss-parser.min.js » 
was blocked because of type MIME (« text/html ») incorrect (X-Content-Type-Options: nosniff)

using this html :

 <script type="application/javascript" src="/node_modules/rss-parser/dist/rss-parser.min.js"></script>

Guill4um avatar May 01 '19 17:05 Guill4um

it seems to work pasting the "rss-parser.min.js" content directly in a script block in my index.html file

it's really not a good practice ... i don't know why this mime type is not good : S

Guill4um avatar May 01 '19 17:05 Guill4um

Tofra your example is working ? here : https://github.com/tofra/angular-rss-parser ?

Guill4um avatar May 01 '19 21:05 Guill4um

No, I haven't fixed it there. If you add this https://github.com/bobby-brennan/rss-parser/issues/109#issuecomment-488140522 then it will work. So this issue can be closed (as it has basically nothing to do with the bundle, just with using this with Angular/Ionic

tofra avatar May 01 '19 21:05 tofra

it doesn't work for me :

Add this to package.json

"browser": { "http": false, "https": false }

Run npm install stream timers --save

:/

i can't use parseURL .

Guill4um avatar May 01 '19 21:05 Guill4um

But that was not the issue of this ticket :-) With these additions you did came some steps further.

Do you have a repo where we can check the code? I'll try parseURL tomorrow or in the weekend.

tofra avatar May 01 '19 21:05 tofra

+1, seeing this issue as well in react/TS + yarn project. I am getting cannot resolve errors for http, https, and buffer. The above solution didn't work for me. Any pointers or updates?

sfbaker7 avatar Jul 12 '21 23:07 sfbaker7

It seems that on webpack you must add it to webpack configuration:

your_webpack_configuration = {
  ...,
  resolve: {
    fallback: {
      http: false,
      https: false
    }
  }
}

nighto avatar Sep 12 '23 10:09 nighto