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

getContents of undefined #13

Closed
smussell opened this issue Sep 25, 2014 · 6 comments · Fixed by #14
Closed

getContents of undefined #13

smussell opened this issue Sep 25, 2014 · 6 comments · Fixed by #14

Comments

@smussell
Copy link

I am getting the below error when using this plugin. It is strange, I don't see it when I make individual requests for the files, but it happens every time when I request the full html page. It used to work fine in 0.4.0, this only started with 0.4.1.

 var chain = Q(this._interceptBuffer.getContents());
                                            ^
TypeError: Cannot call method 'getContents' of undefined
    at ServerResponse.mixin.end (.../builder/node_modules/pk-utils/node_modules/connect-injector/lib/connect-injector.js:116:45)
    at ServerResponse.self.(anonymous function) [as end] (.../builder/node_modules/pk-utils/node_modules/connect-injector/node_modules/uberproto/lib/proto.js:61:21)
    at SendStream.notModified (.../builder/node_modules/pk-utils/node_modules/serve-static/node_modules/send/index.js:303:7)
    at SendStream.send (.../builder/node_modules/pk-utils/node_modules/serve-static/node_modules/send/index.js:509:17)
    at onstat (.../builder/node_modules/pk-utils/node_modules/serve-static/node_modules/send/index.js:585:10)
    at Object.oncomplete (fs.js:107:15)
make: [serve] Error 8 (ignored)

I am using the plugin to inject amd wrappers for some files, my usage is as follows:

var inject = injector(function(req, res) {
          return module(req);
        }, function(data, req, res, callback) {
            try {
                console.log(req.url)
                callback(null, 'define(function(require,exports,module){\n' + data.toString() + '\n});');
            }catch (e) {
                console.log(req.url, e);
                callback(null, data, req, res);
            }
        });

@daffl
Copy link
Owner

daffl commented Sep 25, 2014

What are you using the middleware with? express.static or something else? Also can you run your application with DEBUG=connect-injector set and post the output here? Looks like .write is never called but I'm currently not sure why. Version 0.4.1 had a fix because the module broke in Node 0.10.32.

@smussell
Copy link
Author

Yeah, I'm using it with the serve-static middleware, and it appears that its never calling "write" and data is undefined inside "end". I debugged a little more, I think this happens when its sending a 304 not modified. It seems to work if I add something like below, but I'm not sure that is a good way to handle it.

var chain = Q(this._interceptBuffer ? this._interceptBuffer.getContents() : '');

Here are the debug logs:

connect-injector initializing new injector +0ms
connect-injector first time _interceptCheck ran +4ms true
connect-injector resetting to original response.write +0ms

@daffl
Copy link
Owner

daffl commented Sep 25, 2014

Thanks for the info! Sounds like it might be an easy fix. I just need to figure how to write a test for this and will make a new patch release.

@daffl
Copy link
Owner

daffl commented Sep 25, 2014

Made a 0.4.2 release which should fix the issue.

@constfun
Copy link

Fyi, doesn't look like 0.4.2 is up on npm.

I hit this issue running with browserSync, 0.4.2 installed off GH works.

@daffl
Copy link
Owner

daffl commented Nov 14, 2014

Odd... maybe grunt release choked. Just republished so 0.4.2 should be up now.

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

Successfully merging a pull request may close this issue.

3 participants