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 when doing require('node-read') #26

Open
shaimo opened this issue Nov 24, 2015 · 17 comments
Open

Error when doing require('node-read') #26

shaimo opened this issue Nov 24, 2015 · 17 comments
Labels

Comments

@shaimo
Copy link

shaimo commented Nov 24, 2015

I'm getting:

Uncaught TypeError: Cannot convert undefined or null to object

Seems to happen here:

function getInverseObj(obj){
    return Object.keys(obj).sort().reduce(function(inverse, name){
        inverse[obj[name]] = "&" + name + ";";
        return inverse;
    }, {});
}

Without the require my project runs without an issue...
Am I missing some dependency or anything?

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

did you do npm install node-read ? what node version are you using?

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

Yes, I installed node-read 0.1.6. I probably should have mentioned that I'm actually using it in the browser with browserify. I used node-readability before and wanted to try node-read instead...

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

The code that you provided doesn't come from node-read. I can't really debug it. Can you provide some more context?

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

@bndr let me try. Looking into the calling stack I see the following:

var readability = require('node-read'); // In my file
|
var cheerio = require('cheerio'); // In node_modules/node-read/index.js../lib/utils.js
|
exports = module.exports = require('./lib/cheerio'); // In node_modules/cheerio/index.js../lib/cheerio
|
    parse = require('./parse'), // In node_modules/cheerio/lib/cheerio.js../api/attributes
|
    utils = require('./utils'), // In node_modules/cheerio/lib/parse.js../utils
|
var entities = require('entities'); // In node_modules/cheerio/lib/utils.js.entities

|
var encode = require("./lib/encode.js"), // In node_modules/entities/index.js../lib/decode.js
|
var inverseXML = getInverseObj(require("../maps/xml.json")), // In node_modules/entities/lib/encode.js.../maps/entities.json

Does this help at all?

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

I've updated the cheerio dependency version, can you try it again?

Version 0.1.7 of node-read

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

I updated to 0.1.7 but it didn't seem to update anything about cheerio. npm ls cheerio yields:

In any case still getting the same error

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

I don't really know what the problem is, I never used browserify.

Maybe you can try this: https://wzrd.in/standalone/node-read@latest

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

I don't think it's got to do with browserify - if I replace node-read with node-readability everything works just fine.
I guess I'll stick with node-readability in the meantime...
Thanks for trying to help!

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

How are you calling browserify? did you try with --standalone?

@bndr bndr added the bug label Nov 24, 2015
@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

I'm not calling it directly. My server side is rails and I use the gem browserify-rails. Seems to work nicely as it allows me to write complex javascript with support for commonjs, React, etc. Not sure how to use it separately...

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

According to the readme at https://github.com/browserify-rails/browserify-rails/blob/master/README.md
You can change the command line options in config/application.rb

  # Command line options used when running browserify
  #
  # can be provided as an array:
  config.browserify_rails.commandline_options = ["-t browserify-shim", "--fast"]

  # or as a string:
  config.browserify_rails.commandline_options = "-t browserify-shim --fast"

Can you try adding --standalone?

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

ok, tried it. Loads ok with node-readability but still getting an error with node-read, albeit a different one. Here is the error and "calling stack":

Uncaught TypeError: Cannot read property '0' of undefined

var readability = require('node-read'); // My file
|
var cheerio = require('cheerio'); // In node_modules/node-read/index.js../lib/utils.js
|
exports = module.exports = require('./lib/cheerio'); // In node_modules/cheerio/index.js../lib/cheerio
|
require('./api/traversing'), // In node_modules/cheerio/lib/cheerio.js../api/attributes
|
select = require('css-select'), // In node_modules/cheerio/lib/api/traversing.js.../utils
|
var Pseudos       = require("./lib/pseudos.js"), // In node_modules/css-select/index.js../lib/compile.js
|
var DomUtils    = require("domutils"), // In node_modules/css-select/lib/pseudos.js../attributes.js
|
arguments[4]["/Users/xxx-mbp/dev/ruby/project/node_modules/CSSselect/node_modules/domutils/index.js"][0].apply(exports,arguments) // In node_modules/domutils/index.js../lib/helpers

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

What version of browserify is installed? browserify --version

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

9.0.7

@bndr
Copy link
Owner

bndr commented Nov 24, 2015

Can you try upgrading it to 12.0.1?

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

I think 9.0.7 is what I have installed globally but as part of my project I have

So I think it is ok.
I tried to upgrade the global version too but got some errors. Will have to work on it later...

@shaimo
Copy link
Author

shaimo commented Nov 24, 2015

Was just a sudo missing. Updated global browserify to 12.0.1 but still getting same error when requiring node-read...

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