Javascript Heroku找不到车把部件

Javascript Heroku找不到车把部件,javascript,heroku,handlebars.js,partials,Javascript,Heroku,Handlebars.js,Partials,我完全被这个问题迷住了,我肯定我现在一定是瞎了,但我无法解决它。Heroku正在为确实存在的部分返回“找不到部分”错误(见下文) 注意:这一切都可以在本地主机上完美运行 使用 节点:10.5.0 表达式:4.16.3 哈佛商学院:4.0.1 文件结构: | > Server | > server.js | > Views | > layout.hbs | > Partials | > pageheader.hbs server/ser

我完全被这个问题迷住了,我肯定我现在一定是瞎了,但我无法解决它。Heroku正在为确实存在的部分返回“找不到部分”错误(见下文)

注意:这一切都可以在本地主机上完美运行

使用

  • 节点:10.5.0
  • 表达式:4.16.3
  • 哈佛商学院:4.0.1
文件结构:

| > Server
|   > server.js
| > Views
|   > layout.hbs
|   > Partials
|     > pageheader.hbs
server/server.js

let app = express();

hbs.registerPartials(__dirname + '\\..\\views\\partials');
app.set('view engine', 'hbs');

app.get('/', (req, res) => {
  res.render('layout.hbs', {
    title: 'Home'
  }
});
...
<body>
    {{> pageheader}}
</body>
...
<h1>{{title}}</h1>
视图/布局.hbs

let app = express();

hbs.registerPartials(__dirname + '\\..\\views\\partials');
app.set('view engine', 'hbs');

app.get('/', (req, res) => {
  res.render('layout.hbs', {
    title: 'Home'
  }
});
...
<body>
    {{> pageheader}}
</body>
...
<h1>{{title}}</h1>
。。。
{{>pageheader}
...
视图/部分/pageheader.hbs

let app = express();

hbs.registerPartials(__dirname + '\\..\\views\\partials');
app.set('view engine', 'hbs');

app.get('/', (req, res) => {
  res.render('layout.hbs', {
    title: 'Home'
  }
});
...
<body>
    {{> pageheader}}
</body>
...
<h1>{{title}}</h1>
{{title}
最后

Heroku日志

/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:266
throw new _exception2['default']('The partial ' + options.name + ' could not be found');
^
Error: The partial pageheader could not be found
at Object.invokePartial (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:266:11)
at Object.invokePartialWrapper [as invokePartial] (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
at Object.eval [as main] (eval at createFunctionContext (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:12:28)
at main (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
at ret (/app/node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)
at ret (/app/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21)
at render_file (/app/node_modules/hbs/lib/hbs.js:49:23)
at render_with_layout (/app/node_modules/hbs/lib/hbs.js:80:5)
at cacheAndCompile (/app/node_modules/hbs/lib/hbs.js:151:5)
at /app/node_modules/hbs/lib/hbs.js:171:7
at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
/app/node\u modules/handlebar/dist/cjs/handlebar/runtime.js:266
抛出新的_exception2['default']('The partial'+options.name+'找不到”);
^
错误:找不到部分页眉
在Object.invokePartial(/app/node_modules/handlebar/dist/cjs/handlebar/runtime.js:266:11)
在Object.invokePartialWrapper[作为invokePartial](/app/node_modules/handlebar/dist/cjs/handlebar/runtime.js:68:39)
在Object.eval[as main](在createFunctionContext(/app/node_modules/handlebar/dist/cjs/handlebar/compiler/javascript compiler.js:254:23)处求值:12:28)
在main(/app/node_modules/handlebar/dist/cjs/handlebar/runtime.js:173:32)
ret时(/app/node_modules/handlebar/dist/cjs/handlebar/runtime.js:176:12)
在ret(/app/node_modules/handlebar/dist/cjs/handlebar/compiler/compiler.js:525:21)
在render_文件(/app/node_modules/hbs/lib/hbs.js:49:23)
在使用_布局进行渲染时(/app/node_modules/hbs/lib/hbs.js:80:5)
在cacheAndCompile(/app/node_modules/hbs/lib/hbs.js:151:5)
at/app/node_modules/hbs/lib/hbs.js:171:7
在FSReqWrap.readFileAfterClose[as oncomplete](内部/fs/read_file_context.js:53:3)

我感谢任何帮助/建议,我搜索过谷歌,阅读过任何我能找到的似乎相关的东西。我只是不明白为什么这在本地主机上有效而在Heroku上无效。

我认为文件路径是错误的,请尝试更改

__dirname + '\\..\\views\\partials'


所以。。。我想我已经发现了路径的“…”部分的问题


我已将server.js移动到root,并更改了文件引用以匹配该更改。。。现在,它在任何地方都可以正常工作。

如果我直接在布局中放置{{title}},而不引用分部,则可能值得注意。整个事情确实如预期的那样起作用。这不是一个问题,两者都是有效的,应该起作用。