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 ./~/rss-parser/index.js Module not found: Error: Cannot resolve module 'fs'... #20

Closed
neeilya opened this issue Oct 6, 2016 · 7 comments

Comments

@neeilya
Copy link

neeilya commented Oct 6, 2016

Hey, I've just downloaded and included your module in my project.
I am using webpack for bundling.

All I did is just included package in main.js like this:

import rss-parser from 'rss-parser';

It results an error:

ERROR in .//rss-parser/index.js Module not found: Error: Cannot resolve module 'fs' in /path/to/project/root/node_modules/rss-parser @ .//rss-parser/index.js 2:9-22

In webpack I use only babel-loader and json-loader.

My package.json dependencies:

"dependencies": {
    "babel-core": "^6.17.0",
    "babel-loader": "^6.2.5",
    "babel-preset-es2015": "^6.16.0",
    "copy-webpack-plugin": "^3.0.1",
    "json-loader": "^0.5.4",
    "rss-parser": "^2.5.2",
    "webpack": "^1.13.2"
}

Could you please help me to resolve this issue?
Thanks!

@rbren
Copy link
Owner

rbren commented Oct 6, 2016

Ahh webpack.

There are two entry points to rss-parser: ./index.js, which is a nodejs module, and ./dist/rss-parser.js, which is generated by browserify for use in the browser. It looks like webpack has resolved ./index.js

Can you try

require('./node_modules/rss-parser/dist/rss-parser.js')

instead of

import rss-parser from rss-parser

@neeilya
Copy link
Author

neeilya commented Oct 7, 2016

Can you try
require('./node_modules/rss-parser/dist/rss-parser.js')

Thanks, that works!

@neeilya neeilya closed this as completed Oct 7, 2016
@necronet
Copy link

but one also get the warning

3:482-489 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
 @ ../~/rss-parser/dist/rss-parser.js 3:482-489```

Do you know how to fix it 

@rbren
Copy link
Owner

rbren commented Jan 20, 2017

Are you using webpack?

You can try adding

{
  node: {
    fs: "empty"
  }
}

to your config. Obviously calls to RSSParser.parseFile() will fail, but parseURL and parseString should work.

@shaggiizzle
Copy link

@bobby-brennan where exactly in the webpack.config.js would the
{
node: {
fs: "empty"
}
}
section go?

@rbren
Copy link
Owner

rbren commented Sep 28, 2017

It goes in the top level, e.g.

var config = module.exports = {
    node: {
        fs: "empty"
    }
}

@DreaminDani
Copy link

Thanks @bobby-brennan. I'm using next.js so I had to update the next.config.js file: https://github.com/zeit/next.js#customizing-webpack-config

Simply adding config.node = {fs: "empty"}; in the webpack: (config) arrow function allowed the page to compile successfully.

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