客户端需要(节点模块给出 DEP 错误)

require on client side (node module gives a dep error)

本文关键字:DEP 错误 模块 节点 客户端      更新时间:2023-09-26

我正在尝试使用browserify将我的js捆绑到一个文件中,并能够在客户端使用require。

但是每次我在应用程序上运行浏览器化或观看时.js我都会从 i18next 模块收到错误。

Error: Cannot find module 'jquery' from '/home/js/testapp/node_modules/i18next/lib/dep'

我已经检查了 i18next,它不需要 jquery(如果它不可用)(运行服务器时没有给出任何错误)。

我试过安装 jquery,这个问题消失了,但出现了其他问题:

/home/js/testapp/node_modules/i18next/lib/dep/i18next.js:1245
        $.fn.i18n = function (options) {
                  ^
TypeError: Cannot set property 'i18n' of undefined

我在这里错过了什么?

谢谢

似乎需要禁用jQuery。

在 i18n init 中添加了一个配置(在文档中:http://i18next.com/pages/doc_jquery.html)

setJqueryExt: false

现在我有了这个配置,没有错误

app.use(i18n.handle);
i18n.init({
    cookieName: 'lang',
    fallbackLng: 'en',
    debug: 'true',
    setJqueryExt: false
});