模块在开发中有效,但在heroku中不起作用:nodejs和hbs把手

问题描述 投票:0回答:1

更新的问题:

在本地开发中,模块正在运行。当我推送到heroku时,一个模块似乎不起作用,没有将变量传递给帮助程序。

我的助手文件夹:

ad.helper.js
car.helper.js
pagination.helper.js
urlPagination.helper.js

pagination.helper.js包含:

const hbs = require('hbs');
const paginate = require('handlebars-paginate');
hbs.registerHelper('paginate', paginate);

某些警报处于require('halndlebars-paginate')] >>

module "/home/santiago/code/folder/projectName/node_modules/handlebars-paginate/index"
Could not find a declaration file for module 'handlebars-paginate'. '/home/santiago/code/folder/projectName/node_modules/handlebars-paginate/index.js' implicitly has an 'any' type.
  Try `npm install @types/handlebars-paginate` if it exists or add a new declaration (.d.ts) file containing `declare module 'handlebars-paginate';`ts(7016)

查看帮助程序的位置=> lis.hbs,其中包含:

 {{#paginate pagination type="first"}}
      <a {{#if disabled}}class="disabled"{{/if}} 
      href="{{#urlPagination parentCategory state category n searchWord vendor ageLow ageHigh vendorType priceLow priceHigh brand carmodel km yearLow yearHigh ccLow ccHigh}}{{/urlPagination}}"><li>Primera</li></a>
    {{/paginate}}
    {{#paginate pagination type="previous"}}
      <a {{#if disabled}}class="disabled"{{/if}} 
      href="{{#urlPagination parentCategory state category n searchWord vendor ageLow ageHigh vendorType priceLow priceHigh brand carmodel km yearLow yearHigh ccLow ccHigh}}{{/urlPagination}}"><li>Menos</li></a>
    {{/paginate}}
    {{#paginate pagination type="middle" limit="5"}}
      <a {{#if active}}class="active"{{/if}} href="{{#urlPagination parentCategory state category n searchWord vendor ageLow ageHigh vendorType priceLow priceHigh brand carmodel km yearLow yearHigh ccLow ccHigh}}{{/urlPagination}}"><li >{{n}}</li></a>
    {{/paginate}}
    {{#paginate pagination type="next"}}
      <a {{#if disabled}}class="disabled"{{/if}} href="{{#urlPagination parentCategory state category n searchWord vendor ageLow ageHigh vendorType priceLow priceHigh brand carmodel km yearLow yearHigh ccLow ccHigh}}{{/urlPagination}}"><li>Más</li></a>
    {{/paginate}}
    {{#paginate pagination type="last"}}
      <a {{#if disabled}}class="disabled"{{/if}} href="{{#urlPagination parentCategory state category n searchWord vendor ageLow ageHigh vendorType priceLow priceHigh brand carmodel km yearLow yearHigh ccLow ccHigh}}{{/urlPagination}}"><li>Última</li></a>
    {{/paginate}}

[当我在控制器中使用console.log parentCategory时,我看到了,但是如果我在urlpagination.helper中使用console.log,则它是未定义的。

所以,我认为该模块无法在生产环境中使用(heroku,但我不明白为什么要在开发环境中使用它。

旧问题:

这个模块有些事情我几天都没搞清楚。

这是npm软件包:

https://github.com/olalonde/handlebars-paginate

我正在使用车把。在我的助手文件夹中,我有:

const hbs = require('hbs');
const paginate = require('handlebars-paginate');
hbs.registerHelper('paginate', paginate);

在我的文本编辑器中,我可以看到此警告:

Could not find a declaration file for module 'handlebars-paginate'. '/home/santiago/code/folder/nameProject/node_modules/handlebars-paginate/index.js' implicitly has an 'any' type.
  Try `npm install @types/handlebars-paginate` if it exists or add a new declaration (.d.ts) file containing `declare module 'handlebars-paginate';`

我试图同时解决这两个问题。

[第一个,抛出错误,所以我创建了一个.d.ts文件,警告消失了。之后,仍然无法在heroku(生产模式)下工作。

我不使用打字稿,我认为第二种解决方案不适合我,为什么会出现此警告?(注意:当我创建此文件时,即使我尝试了很多次寻找gitignore,它也没有上传到heroku。)

有趣的是,它在开发(本地主机)中工作得绝对完美,但是在heroku中,它仅在此模块-分页中不起作用。

我做错了什么?为什么看起来像TS错误?

我是新手。请帮助,我即将完成我的第一个项目!

更新的问题:在本地开发中,模块正在运行。当我推送到heroku时,一个模块看起来好像不起作用,没有将变量传递给助手。我的助手文件夹:ad.helper ....

node.js heroku handlebars.js
1个回答
0
投票

我解决了。我认为这是一个非常愚蠢的错误,关于require modules中的路径

© www.soinside.com 2019 - 2024. All rights reserved.