从 lodash 3 到 lodash 4 的迁移:什么取代了“lodash/string/template”?

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

我们尝试将一个 Backbone.js 项目从 lodash“3.10.1”迁移到最新的 lodash“4.17.21”,并且似乎在版本 4 中删除了“lodash/string/template”。

在我们的代码中,我们有这样的东西:

import template from 'lodash/string/template';

export default _.extend(window.app, {
...
    template: (path, options) => template(someCustomMethod(path), options),
...

安装 lodash 4 后,捆绑程序崩溃:

Error: Can't walk dependency graph: Cannot find module 'lodash/string/template'...

以防我以这种方式导入它:

import { template } from 'lodash';

然后编译通过,但是当您尝试加载应用程序时会发生错误:

...Uncaught TypeError: Cannot set properties of undefined (setting '_url_prefix')

它来自“Backbone.View”内部,似乎与 lodash 模板有关。

有人遇到过这样的问题吗? Backbone.js 版本是 1.1.2,但我认为它不相关 - 如果我返回到 lodash“3.10.1”,那么一切正常。也许新的 lodash 模板版本会返回不同结构的结果?

javascript templates backbone.js lodash
1个回答
0
投票

听起来像你想要的

import template from 'lodash/template';

对于

_url_prefix
错误,如果没有完整的堆栈跟踪,就不可能说更多。

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