node-read
node-read copied to clipboard
Error when doing require('node-read')
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?
did you do npm install node-read ? what node version are you using?
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...
The code that you provided doesn't come from node-read. I can't really debug it. Can you provide some more context?
@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?
I've updated the cheerio dependency version, can you try it again?
Version 0.1.7 of node-read
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
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
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!
How are you calling browserify? did you try with --standalone?
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...
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?
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
What version of browserify is installed? browserify --version
9.0.7
Can you try upgrading it to 12.0.1?
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...
Was just a sudo missing. Updated global browserify to 12.0.1 but still getting same error when requiring node-read...