【问题标题】:Why are node modules working on firebase emulator but not working post deployment?为什么节点模块在 firebase 模拟器上工作但在部署后不工作?
【发布时间】:2021-01-16 15:44:01
【问题描述】:

我在使用 npm 安装的项目中使用 intl-tel-input。当我使用 Firebase 模拟器进行测试时,一切似乎都运行良好,但在部署后停止工作。

在 Chrome 开发工具中检查 Sources 选项卡后,我可以看到该模块未正确包含。 (请检查图片)但是,我完全无法弄清楚为什么。请帮忙!

Emulator Screenshot with the Telephone Input field working fine.

Screenshot taken post deployment with the Telephone input field broken.

Source File - intlTelInput.js located at /node_modules/intl-tel-input/build/css/intlTelInput.js

Source File - intlTelInput.css located at /node_modules/intl-tel-input/build/js/intlTelInput.css

【问题讨论】:

    标签: firebase node-modules web-deployment firebase-hosting intl-tel-input


    【解决方案1】:

    默认情况下 Firebase ignores node_modules 部署时的目录。

    您可以使用几个选项来解决此问题。

    1. 使用 Rollup 或 Webpack 等构建工具生成包含节点依赖项的包。
    2. 将所需的 node_modules 文件复制到不同的目录,例如 assets,然后从那里加载它们。
    3. 更新 firebase.json 以在部署时不忽略 node_modules。请注意,如果您有任意数量的节点包,这可能会大大增加已部署应用程序的大小。

    【讨论】:

    • 我设法通过使用上面给出的建议编号 (3) 自己解决了这个问题。为了避免降低应用程序的速度,我不得不将未使用的节点包移动到不同的目录或完全删除它们。为了成功完成部署,我必须删除 .firebase 文件夹中的缓存。总而言之,这种方法奏效了。感谢您的帮助。
    猜你喜欢
    • 2021-11-11
    • 2015-08-05
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 2020-12-10
    • 2012-08-19
    相关资源
    最近更新 更多