OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Uncaught TypeError express-handlebars

  • Thread starter Thread starter Мария Углова
  • Start date Start date
М

Мария Углова

Guest
I'm trying to connect to express-handlebars. This is my index.ts:


Code:
import * as express from 'express';
import { engine } from 'express-handlebars';

const app = express();

app.engine('handlebars', engine());
app.set('view engine', 'handlebars');
app.set('views', './pages');

app.get('/', (req, res) => {
    res.render('home');
});

app.listen(3000);

This is my vite.config.mjs


Code:
import { resolve } from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
    server: {
        open: '/',
    },
    root: resolve(__dirname, 'src'),
    build: {
        outDir: resolve(__dirname, 'dist'),
    },
});

This is my package.json:


Code:
{
...
  "scripts": {
    "dev": "vite"
  },
  "engines": {
    "node": ">=16.0.0"
  },
  "devDependencies": {
    "@types/express": "^4.17.21",
    "@types/node": "^20.14.5",
    "sass": "^1.77.4",
    "ts-node": "^10.9.2",
    "typescript": "^5.4.5",
    "vite": "^5.2.0"
  },
  "dependencies": {
    "express": "^4.19.2",
    "express-handlebars": "^7.1.3",
    "handlebars": "^4.7.8",
    "handlebars-loader": "^1.7.3",
    "uuid": "^10.0.0",
    "vite-plugin-checker": "^0.6.4",
  }
}

And unfortunately I get an error in the console: Uncaught TypeError: Cannot read properties of undefined (reading 'from')

Why does the error appear? Thanks in advance for any help.

<p>I'm trying to connect to express-handlebars.
This is my index.ts:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import * as express from 'express';
import { engine } from 'express-handlebars';

const app = express();

app.engine('handlebars', engine());
app.set('view engine', 'handlebars');
app.set('views', './pages');

app.get('/', (req, res) => {
res.render('home');
});

app.listen(3000);</code></pre>
</div>
</div>
</p>
<p>This is my vite.config.mjs</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>import { resolve } from 'path';
import { defineConfig } from 'vite';

export default defineConfig({
server: {
open: '/',
},
root: resolve(__dirname, 'src'),
build: {
outDir: resolve(__dirname, 'dist'),
},
});</code></pre>
</div>
</div>
</p>
<p>This is my package.json:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>{
...
"scripts": {
"dev": "vite"
},
"engines": {
"node": ">=16.0.0"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/node": "^20.14.5",
"sass": "^1.77.4",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"vite": "^5.2.0"
},
"dependencies": {
"express": "^4.19.2",
"express-handlebars": "^7.1.3",
"handlebars": "^4.7.8",
"handlebars-loader": "^1.7.3",
"uuid": "^10.0.0",
"vite-plugin-checker": "^0.6.4",
}
}</code></pre>
</div>
</div>
</p>
<p>And unfortunately I get an error in the console:
Uncaught TypeError: Cannot read properties of undefined (reading 'from')</p>
<p>Why does the error appear?
Thanks in advance for any help.</p>
 

Latest posts

Online statistics

Members online
1
Guests online
2
Total visitors
3
Top