当我试图构建我的车把项目时,我正在经历可怕的not an "own property" of its parent问题。
我一直在兔子洞,看到了许多解释使用@handlebars/allow-prototype-access允许问题被绕过,但项目似乎没有使用一个标准的实现把手.
我好像在用一个叫做engine-handlebars的东西
在我期望实现allow-prototype-access更改的地方,我看到了以下内容:
app.pages('./source/pages/**/*.hbs');
app.engine('hbi', require('engine-handlebars'));我不知道如何用这个设置实现原型访问.
似乎,经过一些试验和错误,注释行,在我走,行app.pages('./source/pages/**/*.hbs');实际上是造成了这个问题.
当我使用这一行运行项目时,我会得到以下错误:
Handlebars: Access has been denied to resolve the property "path" because it is not an "own property" of its parent.
You can add a runtime option to disable the check or this warning:
See https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access for details
[10:54:49] ERROR - undefined: Cannot read property 'substring' of undefined发布于 2022-02-15 22:39:05
插件@车把/允许-原型-访问通过修改Handlebars实例来工作。
const _Handlebars = require('handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');
const Handlebars = allowInsecurePrototypeAccess(_Handlebars);注意,
allowInsecurePrototypeAccess没有修改实例,而是通过Handlebars.create()创建了一个孤立实例,因此必须使用它的返回值。
在您的示例中,发动机把手以不同的方式公开Handlebars实例,具体取决于您使用的版本。
根据您提供的代码,我猜您正在使用<1.0.0,但我将为其所有版本提供调整方法。
发动机-车把@<0.6.0
不幸的是,这些版本没有以任何方式公开Handlebars,所以如果您正在使用此版本,我建议将引擎把手升级到更高版本。
发动机-车把@>=0.6.0 <1.0.0
0.6.0版曝光 Handlebars作为导出引擎函数上的属性。然后通过this.Handlebars在整个库中引用这一点。
然后,您可以在设置app.engine()之前更改它,并且它应该可以工作。
const _Handlebars = require('handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');
const engine = require('engine-handlebars');
// elsewhere...
// const app = ...
// Do this *before* setting app.engine
const insecureHandlebars = allowInsecurePrototypeAccess(_Handlebars);
engine.Handlebars = insecureHandlebars;
app.engine('hbi', engine);引擎-车把@>=1.0.0
对于1.0.0版和更高版本,您必须自己传递Handlebars实例。
const Handlebars = require('handlebars');
const engine = require('engine-handlebars')(Handlebars);因此,您不需要在engine上设置任何内容,只需在需要时传入修改过的实例。
const _Handlebars = require('handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');
// elsewhere...
// const app = ...
// Do this *before* setting app.engine
const insecureHandlebars = allowInsecurePrototypeAccess(_Handlebars);
const engine = require('engine-handlebars')(insecureHandlebars);
app.engine('hbi', engine);https://stackoverflow.com/questions/71124348
复制相似问题