[英]TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received an instance of Object
[英]ERR_INVALID_ARG_TYPE - The “from” argument must be of type string. Received an instance of Array
我正在嘗試為視圖文件夾添加兩個目錄。 在文檔中,我發現您可以添加字符串或數組以添加多個視圖文件夾。
一個用於管理面板,另一個用於網站/公共使用。
所以我通過以下方式添加:
/**
* setting up the view engine
*/
app.engine('handlebars', hbs({
defaultLayout: "main"
}));
app.set('view engine', 'handlebars');
app.set('views', [path.join(__dirname, 'views'), path.join(__dirname, 'public-views/zubizi-theme')]);
// end view engine setup
我收到以下錯誤:
TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received an instance of Array
(node:108) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received an instance of Array
at validateString (internal/validators.js:117:11)
at Object.relative (path.js:437:5)
at ExpressHandlebars.renderView (F:\zubizi\cms\files\node_modules\express-handlebars\lib\express-handlebars.js:193:38)
at View.render (F:\zubizi\cms\files\node_modules\express\lib\view.js:135:8)
at tryRender (F:\zubizi\cms\files\node_modules\express\lib\application.js:640:10)
at Function.render (F:\zubizi\cms\files\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (F:\zubizi\cms\files\node_modules\express\lib\response.js:1008:7)
at F:\zubizi\cms\files\routes\admin.js:7:6
at Layer.handle [as handle_request] (F:\zubizi\cms\files\node_modules\express\lib\router\layer.js:95:5)
at next (F:\zubizi\cms\files\node_modules\express\lib\router\route.js:137:13)
(node:108) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:108) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
.
這是我的文件夾結構,如下所示:
.
我在我的應用程序中使用以下技術:
NodeJS 模板引擎: express-handlebars
。
ExpressJS版本: 4.16.0
節點JS版本: v12.16.3
有一個開放的 PR 來支持作為數組傳入的多個視圖目錄: https : //github.com/ericf/express-handlebars/pull/209
現在,您需要修復您的設置並將您的視圖合並到一個目錄中並僅傳遞該目錄:
app.set('views', './path-to-views-folder')
;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.