英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论