从 lodash 3 迁移到 lodash 4:’lodash/string/template’ 被什么替代?

huangapple go评论64阅读模式
英文:

Migration from lodash 3 to lodash 4: what replaces the 'lodash/string/template'?

问题

我们尝试将一个Backbone.js项目从lodash "3.10.1"迁移到最新的lodash "4.17.21",似乎'lodash/string/template'在版本4中已被移除。

在我们的代码中,有类似这样的内容:

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模板版本返回了不同结构的结果?

英文:

We try to migrate one Backbone.js project from lodash "3.10.1" to latest lodash "4.17.21" and seems like 'lodash/string/template' was removed in version 4.

In our code we have something like:

import template from 'lodash/string/template';

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

And with lodash 4 installed the bundler crashes with:

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

In case I import it this way:

import { template } from 'lodash';

Then compilation passes but when you try to load the app then an error occurs:

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

It comes from inside "Backbone.View" and seems related to lodash template.

Have someone stumbled upon such an issue? The Backbone.js version is 1.1.2, but I think it's not related - if I return back to lodash "3.10.1" then all works perfectly. Maybe the new lodash template version returns differently structured results?

答案1

得分: 1

听起来你想要

import template from 'lodash/template';

至于 _url_prefix 错误,没有完整的堆栈跟踪无法提供更多信息。

英文:

It sounds like you want

import template from 'lodash/template';

and for the _url_prefix error it's impossible to say more without the full stack trace.

huangapple
  • 本文由 发表于 2023年2月14日 00:31:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定