rbren / rss-parser

A lightweight RSS parser, for Node and the browser
MIT License
1.39k stars 209 forks source link

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

Open Guill4um opened 5 years ago

Guill4um commented 5 years ago

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 !

rbren commented 5 years ago

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

tofra commented 5 years ago

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)

Guill4um commented 5 years ago

i'm runnign my test in firefox

rbren commented 5 years ago

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

tofra commented 5 years ago

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

rbren commented 5 years ago

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

tofra commented 5 years ago

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

tofra commented 5 years ago

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

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

Run npm install stream timers --save

rbren commented 5 years ago

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

Guill4um commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

tofra commented 5 years ago

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

Guill4um commented 5 years ago

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 .

tofra commented 5 years ago

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.

sfbaker7 commented 3 years ago

+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?

nighto commented 1 year ago

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

your_webpack_configuration = {
  ...,
  resolve: {
    fallback: {
      http: false,
      https: false
    }
  }
}
opeolluwa commented 1 month ago

Hello Here @nighto @tofra i appreciate your solutions to these issues but none works for me

I have a Vu2 2.x project that uses vue-cli v2, Webpack 3.x.

I updated the vue-cli, webpack and the webpack plugins to v5 but I'm gettig this error


ERROR in ./node_modules/rss-parser/lib/parser.js 2:13-28
Module not found: Error: Can't resolve 'http' in '/app/node_modules/rss-parser/lib'

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 }

Module not found: Error: Can't resolve 'https' in '/app/node_modules/rss-parser/lib'

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 }