nodebook
nodebook copied to clipboard
Can't run Chapter 7.
When I run the Chapter 7 version of the files, I keep getting an error message.
Express
500 TypeError: Cannot call method 'replace' of undefined
at model.<anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\models\image.js:16:30)
at VirtualType.applyGetters (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\virtualtype.js:77:25)
at model.Document.get (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\document.js:711:18)
at model.Object.defineProperty.get [as uniqueId] (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\document.js:1228:45)
at program1 (eval at <anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), <anonymous>:11:36)
at prog (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:118:12)
at Object.<anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\base.js:99:23)
at Object.eval (eval at <anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), <anonymous>:26:25)
at C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:86:31
at C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:465:21
at model.<anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\models\image.js:16:30)
at VirtualType.applyGetters (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\virtualtype.js:77:25)
at model.Document.get (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\document.js:711:18)
at model.Object.defineProperty.get [as uniqueId] (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\document.js:1228:45)
at program1 (eval at <anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), <anonymous>:11:36)
at prog (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:118:12)
at Object.<anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\base.js:99:23)
at Object.eval (eval at <anonymous> (C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), <anonymous>:26:25)
at C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:86:31
at C:\Users\Mark\_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:465:21
Any idea what could be causing this? (I'm using Windows 8.1, in case that makes a difference.)
Hi Mark,
I would start here:
(C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\models\image.js:16:30)
Specifically line 16. That error typically means that you're running .replace on a variable or property thats undefined. So if you have an object of say:
var person = {
name: 'Jason'
};
And you tried to call: person.fullname.replace('Jason', 'Awesome') - you will get the exact same error (since fullname isnt a thing but instead should have been called on .name)
If you can post your sourcecode complete somewhere (like GitHub) I can take a look and help you a little more.
Thanks!
On Tue, Dec 23, 2014 at 1:41 PM, Mark Cancellieri [email protected] wrote:
When I run the Chapter 7 version of the files, I keep getting an error message.
Express 500 TypeError: Cannot call method 'replace' of undefined at model.
(C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\models\image.js:16:30) at VirtualType.applyGetters (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\virtualtype.js:77:25) at model.Document.get (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\document.js:711:18) at model.Object.defineProperty.get as uniqueId at program1 (eval at (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), :11:36) at prog (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:118:12) at Object. (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\base.js:99:23) at Object.eval (eval at (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), :26:25) at C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:86:31 at C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:465:21 at model. (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\models\image.js:16:30) at VirtualType.applyGetters (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\virtualtype.js:77:25) at model.Document.get (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\mongoose\lib\document.js:711:18) at model.Object.defineProperty.get as uniqueId at program1 (eval at (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), :11:36) at prog (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:118:12) at Object. (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\base.js:99:23) at Object.eval (eval at (C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compiler.js:189:23), :26:25) at C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\runtime.js:86:31 at C:\Users\Mark_TEST\nodebook-master\nodebook-master\chapter7\node_modules\express3-handlebars\node_modules\handlebars\dist\cjs\handlebars\compiler\compiler.js:465:21 Any idea what could be causing this? (I'm using Windows 8.1, in case that makes a difference.)
— Reply to this email directly or view it on GitHub https://github.com/jkat98/nodebook/issues/11.
Jason [email protected] | 267.980.7912
@ShortTompkins http://twitter.com/ShortTompkins /in/jasonkrol http://linkedin.com/in/jasonkrol kroltech.com
Jason,
All I did was download your source code from GitHub, move to the Chapter 7 directory, run npm install
, and then node server
. When I went to http://localhost:3300/
, that is when I got the error.
I tried the same thing from the imgploadr
directory (which is the final app, right?), and I got the same error message.
Hey Mark,
Interesting. I just did the same, cloned the repo fresh, went into Chapter7 and did npm install && node server.js and it loaded up fine (after I made sure I was runnign a local instance of mongod that is). Loading the url pulled up the website fine (although with no content and a bunch of broken images). Did you try to actually do anything on the site or literally get that error the instant the site loaded?
On Tue, Dec 23, 2014 at 2:06 PM, Mark Cancellieri [email protected] wrote:
Jason,
All I did was download your source code from GitHub, move to the Chapter 7 directory, run npm install, and then node server. When I went to http://localhost:3300/, that is when I got the error.
I tried the same thing from the imgploadr directory (which is the final app, right?), and I got the same error message.
— Reply to this email directly or view it on GitHub https://github.com/jkat98/nodebook/issues/11#issuecomment-67986703.
Jason [email protected] | 267.980.7912
@ShortTompkins http://twitter.com/ShortTompkins /in/jasonkrol http://linkedin.com/in/jasonkrol kroltech.com
I got the error the instant the site loaded. I didn't do anything.
I was following along with the book fine until chapter 7, but it didn't like this replace
command from the image model:
ImageSchema.virtual('uniqueId')
.get(function() {
return this.filename.replace(path.extname(this.filename), '');
});
That was when I tried to download your code, but I couldn't get that to run either.
Im going to try to run this on my other Windows PC when I get home a little later and see what happens.
Sorry about this. I havent seen this issue before so it has me stumped.
I should get back to you tonight hopefully.
Thanks!
On Tue, Dec 23, 2014 at 2:43 PM, Mark Cancellieri [email protected] wrote:
I got the error the instant the site loaded. I didn't do anything.
I was following along with the book fine until chapter 7, but it didn't like this replace command from the image model:
ImageSchema.virtual('uniqueId') .get(function() { return this.filename.replace(path.extname(this.filename), ''); });
That was when I tried to download your code, but I couldn't get that to run either.
— Reply to this email directly or view it on GitHub https://github.com/jkat98/nodebook/issues/11#issuecomment-67990512.
Jason [email protected] | 267.980.7912
@ShortTompkins http://twitter.com/ShortTompkins /in/jasonkrol http://linkedin.com/in/jasonkrol kroltech.com
I just tried running imgploadr
and chapter7
on my Windows 7 laptop, and they both work (although I had to add the upload
and temp
folders to the chapter7
version). Very strange. So there is something on my Windows 8.1 desktop that is causing it not to work.
If you can't reproduce the error, it's no big deal.
Very weird. I just tried on a Windows 8 PC and all went well. If anything I would say maybe delete the repo and try again. Also double check the version of node you're running on that machine (not that it would be generating an error like that). You want to be running something along the lines of 0.10.33.
Sorry I couldn't be of more help!
Let me know if you run into any other snags. Thanks!
On Tue, Dec 23, 2014 at 4:14 PM, Mark Cancellieri [email protected] wrote:
I just tried running imgploadr and chapter7 on my Windows 7 laptop, and they both work (although I had to add the upload and temp folders to the chapter7 version). Very strange. So there is something on my Windows 8.1 desktop that is causing it not to work.
If you can't reproduce the error, it's no big deal.
— Reply to this email directly or view it on GitHub https://github.com/jkat98/nodebook/issues/11#issuecomment-67999213.
Jason [email protected] | 267.980.7912
@ShortTompkins http://twitter.com/ShortTompkins /in/jasonkrol http://linkedin.com/in/jasonkrol kroltech.com
Jason,
I figured it out. There was only one document saved to the images
collection in the database on my desktop computer, and it was somehow saved without a filename
property, which is why it couldn't find the replace
method. I deleted that document, and now it works fine.
Thanks for your help, and happy holidays!