Closed nvcken closed 9 years ago
I built this using Chrome as my primary browser, so it should work on Chrome for Ubuntu or Firefox. Are you getting a specific error message?
I tried to install this module and use https://github.com/visionmedia/superagent for my test.js But get error Cannot find module 'superagent-no-cache' My code
var assert = require("assert")
var should = require("should")
var request = require('superagent');
var nocache = require('superagent-no-cache');
package.json
"dependencies": {
"chai": "^2.2.0",
"should": "^6.0.1",
"sinon": "^1.14.1",
"superagent": "^1.2.0"
},
and install "component install johntron/superagent-no-cache" Then run mocha -> get error Cannot find module 'superagent-no-cache'
This looks like a naming issue between the component and npm naming of the module. NPM has it registered as superagent-no-cache
while component registers it as no-cache
IIRC (their website is down, so I can't verify that right now). Try using no-cache
naming with component and see how that works.
I'm going to be going through and standardizing the naming registrations here this week, so this shouldn't be an issue much longer.
Nah, the package.json
specifies the same as npm: name: "superagent-no-cache"
. @nvcken can you double check that the component install
updated the component.json dependencies:
"dependencies": {
"chai": "^2.2.0",
"should": "^6.0.1",
"sinon": "^1.14.1",
"superagent": "^1.2.0",
"superagent-no-cache": "<some version>"
},
It's not listed in your last message, so want to confirm.
component.json
{
"dependencies": {
"johntron/superagent-no-cache": "~0.0.1"
}
}
package.json
"dependencies": {
"chai": "^2.2.0",
"should": "^6.0.1",
"sinon": "^1.14.1",
"superagent": "^1.2.0"
},
I feel confuse about component because I see my structure code after install
my_project
components
component
ie
johntron
superagent-no-cache
node_modules
chai
should
sinon
superagent
test.js
package.json
component.json
so the flow I can not figure out is how require code (below) work , because has no module in node-module
var nocache = require('superagent-no-cache')work --> currently not work
or
var nocache = require('no-cache'); ---> has tried as @therebelrobot guide, not work too
-> get error Cannot find module 'no-cache'
@nvcken I was mistaken about the naming issue. I'm not as familiar with component, so definitely @johntron is the one to ask about this. My gut reaction is that the component.json should say superagent-no-cache
rather than johntron/superagent-no-cache
, but that's under the assumption that it works the same way as NPM, which I already know is not the case. So yeah, @johntron, this is all yours.
gingerly puts down mic and slowly backs out of the room
Ah, I think we need to update the Readme. This module was intended to be installed after superagent was already installed – as an addon. If you try to install directly with component install johntron/superagent-no-cache
, it will not install the superagent module for Component.
@nvcken try running component install visionmedia/superagent
. I can see from the JSON files you posted that superagent is installed, but it's the NPM package and you need the Component package for UI code.
@therebelrobot - FYI, Component doesn't do anything with the stuff under node_modules
- these are solely managed by npm (in package.json
). Things installed with Component are put under the components
directory (the user can override this default) and are defined in component.json
.
I didn't define superagent as a dependency, because I assumed the user would've already installed it. When I created this module, I wasn't sure if defining superagent as a dependency would cause problems when other modules that also define superagent as a dependency are installed. I think it's safe, but if two modules define different versions of superagent as a dependency, I'm not sure what would happen.
@nvcken did @johntron's response solve the issue?
@therebelrobot I try, clone this repo Then run
npm install
component install
Finally I run
node index.js
Error occur
ReferenceError: document is not defined
at ie /home/ken/superagent-no-cache/node_modules/component-ie/index.js:16:17
I try again, create new repo folder
npm init
npm install --save superagent-no-cache
component install johntron/superagent-no-cache
create index.js as guide
var request = require('request')
var noCache = require('superagent-no-cache')
request.get('/url')
.use(noCache)
.end(function _requestCallback() {
// do something
});
Then run node index.js Same error
^
ReferenceError: document is not defined
at ie (/home/ken/test_/node_modules/superagent-no-cache/node_modules/component-ie/index.js:16:17)
What I missed ?
@nvcken sorry for your frustration - when I built it, I was using it for the browser via Component; node doesn't have a document
, hence the error. I just realized you're trying to use node. I think this can be fixed by removing this line from package.json: https://github.com/johntron/superagent-no-cache/blob/master/package.json#L31. Try removing this as well as node_modules/component-ie.
Also, if you're not using with Component, you don't have to run the component install
step.
I'm not on my laptop, so I can't try myself or update package.json
and readme
with this info right now. Sorry :\
What you mean "using it for the browser via Component" Could you explain more detail , please , I have no idea about it yet
if remove line as https://github.com/johntron/superagent-no-cache/blob/master/package.json#L31 index.js code not work
try {
ie = require('ie')
} catch (e) {
ie = require('component-ie')
}
Cannot find module 'component-ie'
@nvcken, this module is designed to work in the browser via either browserify for bundling or component. It is not designed to work in node directly. Superagent, iirc, is a browser-side only request system, and this module can only be used if being run in a browser, not the command line or in a node process; there just aren't the resources needed to run it like that. If you need help with how to use component or browserify, I suggest taking a look at their corresponding repos, where they explain a bit more how browser-side commonjs modules (like this one) are used.
That being said, changing the package.json as described does break functionality. Package.json is an npm dependency file, and the only npm package that works with this module is component-ie. Removing that package wouldn't make it work more in node, it would make it work less. If you really do need this to work without a browser environment (which is not supported use of the lib), you would need to find a way of running a headless browser in node, but that's not something either of us can really help with.
@therebelrobot Very clear , Thank you so much for detail explanation. Thanks @johntron.
Ubuntu has no IE, Tell me my wrong please.