mde / ejs

Embedded JavaScript templates -- http://ejs.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read properties of null if CSS is linked

tzwel opened this issue · comments

I'm debugging this for over two hours already

const user = await prisma.User.findFirst({
	where: {
		publicId: req.params.userId
	}
})

console.log(user)

res.render('profile.ejs', {user})

This is the returned user object

  {
    id: 1,
    publicId: 'some id',
    username: '123',
    password: 'passwordhash'
  }

The user gets logged correctly (if the template is mostly empty), ejs renders the template correctly, but logs this error in the console:
Cannot read properties of null (reading 'id')

Once I add CSS into the template
<link rel="stylesheet" href="/card.css">
I get this error

 authorId: user.id
                                       ^

TypeError: Cannot read properties of null (reading 'id')

user.id becomes completely unusable everywhere and will just crash node

This is the weirdest bug i have ever encountered, I am not even sure if this is linked to ejs in any way. The bug seems to change its behavior in some random circumstances I can not pinpoint

Looks like this is unrelated to ejs and happens with jade and mustache as well
https://stackoverflow.com/questions/31329578/why-does-adding-a-css-link-to-my-jade-template-make-my-node-app-crash
https://stackoverflow.com/questions/57242584/page-crashes-whenever-i-link-a-css-stylesheet-on-one-file-but-doesnt-on-anothe

I'll keep this issue open for a while because there's no clear solution for this afaik

	<link rel="stylesheet" href="/card.css">

A single slash like this fixed the problem. Why, I have no idea