Кто-нибудь Помогите пожалуйста
это моя ошибка
SyntaxError: C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\views\register.ejs:7
5| <i class="fas fa-user-plus"></i> Register
6| </h1>
>> 7| <%- include ('partials/messages.ejs') %>
8| <form action="/users/register" method="POST">
9| <div class="form-group">
10| <label for="name">Name</label>
Unexpected token 'catch' in C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\views\partials\messages.ejs while compiling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
at new Function (<anonymous>)
at Template.compile (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:661:12)
at Object.compile (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:396:16)
at handleCache (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:233:18)
at includeFile (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:321:10)
at include (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:689:16)
at eval (eval at compile (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:661:12), <anonymous>:10:17)
at register (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:691:17)
at tryHandleCache (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:272:36)
at View.exports.renderFile [as engine] (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\ejs\lib\ejs.js:489:10)
at View.render (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\express\lib\application.js:640:10)
at Function.render (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\express\lib\response.js:1012:7)
at ServerResponse.res.render (C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\node_modules\express-ejs-layouts\lib\express-layouts.js:77:18)
at C:\Users\Dominic\Desktop\html codes\portfolio\passport-tutorial\routes\users.js:38:7
это регистр. E js файл
<div class="row mt-5">
<div class="col-md-6 m-auto">
<div class="card card-body">
<h1 class="text-center mb-3">
<i class="fas fa-user-plus"></i> Register
</h1>
<%- include ('partials/messages') %>
<form action="/users/register" method="POST">
<div class="form-group">
<label for="name">Name</label>
<input
type="name"
id="name"
name="name"
class="form-control"
placeholder="Enter Name"
value="<%= typeof name != 'undefined' ? name : '' %>"
/>
</div>
<div class="form-group">
<label for="email">Email</label>
<input
type="email"
id="email"
name="email"
class="form-control"
placeholder="Enter Email"
value="<%= typeof email != 'undefined' ? email : '' %>"
/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
class="form-control"
placeholder="Create Password"
value="<%= typeof password != 'undefined' ? password : '' %>"
/>
</div>
<div class="form-group">
<label for="password2">Confirm Password</label>
<input
type="password"
id="password2"
name="password2"
class="form-control"
placeholder="Confirm Password"
value="<%= typeof password2 != 'undefined' ? password2 : '' %>"
/>
</div>
<button type="submit" class="btn btn-primary btn-block">
Register
</button>
</form>
<p class="lead mt-4">
Have An Account? <a href="/users/login">Login</a>
</p>
</div>
</div>
</div>
это логин. E js файл
<div class="row mt-5">
<div class="col-md-6 m-auto">
<div class="card card-body">
<h1 class="text-center mb-3">
<i class="fas fa-sign-in-alt"></i> Login
</h1>
<%- include ('partials/messages') %>
<form action="/users/login" method="POST">
<div class="form-group">
<label for="email">Email</label>
<input
type="email"
id="email"
name="email"
class="form-control"
placeholder="Enter Email"
/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
class="form-control"
placeholder="Enter Password"
/>
</div>
<button type="submit" class="btn btn-primary btn-block">
Login
</button>
</form>
<p class="lead mt-4">
No Account? <a href="/users/register">Register</a>
</p>
</div>
</div>
</div>
это мои частичные сообщения. E js
<% if(typeof errors != 'undefined'){ %> <% errors.forEach(function(error) { %>
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<%= error.msg %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<% }); %> <% } %> <% if(success_msg != ''){ %>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<%= success_msg %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<% } %> <% if(error_msg != ''){ %>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<%= error_msg %>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
это мои пользователи. js файл
const express = require("express");
const router = express.Router();
const bcrypt = require("bcryptjs");
//User model
const User = require("../models/User");
//Login page
router.get("/login", (req, res) => {
res.render("login");
});
//Register page
router.get("/register", (req, res) => {
res.render("register");
});
//Registration Post Handler
router.post("/register", (req, res) => {
const { name, email, password, password2 } = req.body;
let errors = [];
//Check required fields
if (!name || !email || !password || !password2) {
errors.push({ msg: "Please fill in all fields" });
}
if (password !== password2) {
errors.push({ msg: "Passwords do not match" });
}
//Check password length
if (password.length < 6) {
errors.push({ msg: "Password must be at least 6 characters long" });
}
if (errors.length > 0) {
res.render("register", {
errors,
name,
email,
password,
password2,
});
} else {
//validating user
User.findOne({ email: email }).then((user) => {
if (user) {
// if User exist
errors.push({ msg: "Email already exist" });
res.render("register", {
errors,
name,
email,
password,
password2,
});
} else {
const newUser = new User({
name,
email,
password,
});
//Hashing Password
bcrypt.genSalt(10, (error, salt) =>
bcrypt.hash(newUser.password, salt, (error, hash) => {
if (error) throw error;
//setting password to hash
newUser.password = hash;
//save user
newUser
.save()
.then((user) => {
req.flash('success_msg','You are now registered and can now sign in')
res.redirect("/users/login");
// console.log(newUser)
})
.catch((error) => console.log(error));
})
);
}
});
}
});
module.exports = router;
Я проверял github и другие онлайн-ресурсы, но не нашел ничего существенного. Я пробовал более ранние версии e js, но по-прежнему имею ту же проблему.
Он работал нормально, пока я не ввел connect-fla sh. Что я делаю не так?