node-read icon indicating copy to clipboard operation
node-read copied to clipboard

Error when doing require('node-read')

Open shaimo opened this issue 9 years ago • 17 comments
trafficstars

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?

shaimo avatar Nov 24 '15 10:11 shaimo

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

bndr avatar Nov 24 '15 10:11 bndr

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...

shaimo avatar Nov 24 '15 10:11 shaimo

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

bndr avatar Nov 24 '15 10:11 bndr

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

shaimo avatar Nov 24 '15 10:11 shaimo

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

Version 0.1.7 of node-read

bndr avatar Nov 24 '15 11:11 bndr

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

└─┬ [email protected]
  └── [email protected] 

In any case still getting the same error

shaimo avatar Nov 24 '15 11:11 shaimo

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

bndr avatar Nov 24 '15 12:11 bndr

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!

shaimo avatar Nov 24 '15 12:11 shaimo

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

bndr avatar Nov 24 '15 12:11 bndr

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...

shaimo avatar Nov 24 '15 12:11 shaimo

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?

bndr avatar Nov 24 '15 12:11 bndr

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

shaimo avatar Nov 24 '15 12:11 shaimo

What version of browserify is installed? browserify --version

bndr avatar Nov 24 '15 13:11 bndr

9.0.7

shaimo avatar Nov 24 '15 13:11 shaimo

Can you try upgrading it to 12.0.1?

bndr avatar Nov 24 '15 13:11 bndr

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

└── [email protected] 

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 avatar Nov 24 '15 13:11 shaimo

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

shaimo avatar Nov 24 '15 13:11 shaimo