简体   繁体   English

使用汇总导入 firebaseui

[英]Import firebaseui with rollup

I am trying to import the firebaseui library with rollup.我正在尝试使用汇总导入firebaseui库。 The ui loads fine if I include firbaseui with the cdn they provide:如果我在他们提供的 cdn 中包含 firbaseui,则 ui 加载良好:

<script src="https://www.gstatic.com/firebasejs/ui/4.5.0/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/4.5.0/firebase-ui-auth.css" />

but if I instead try to import it with import * as firebaseui from 'firebaseui' I get the following error in the browser: Uncaught TypeError: Failed to resolve module specifier "firebaseui". Relative references must start with either "/", "./", or "../".但如果我尝试使用import * as firebaseui from 'firebaseui'导入它,我会在浏览器中收到以下错误: Uncaught TypeError: Failed to resolve module specifier "firebaseui". Relative references must start with either "/", "./", or "../". Uncaught TypeError: Failed to resolve module specifier "firebaseui". Relative references must start with either "/", "./", or "../".

I am using rollup's plugin-node-resolve and plugin-commonjs with this config:我正在使用汇总的 plugin-node-resolve 和 plugin-commonjs 与此配置:

import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";

export default {
  // If using any exports from a symlinked project, uncomment the following:
  // preserveSymlinks: true,
  input: ["src/index.js"],
  output: {
    file: "public/index.js",
    format: "es",
    sourcemap: true,
  },
  plugins: [resolve(), commonjs()],
};

which I thought was meant to handle bare module errors like this, so I don't know how to fix this.我认为这是为了处理这样的裸模块错误,所以我不知道如何解决这个问题。

It turns out this problem is caused by the way firebaseui improperly imports firebase in it's ES module build.事实证明,这个问题是由 firebaseui 在其 ES 模块构建中不正确地导入 firebase 的方式引起的。 I raised an issue here but it got closed.在这里提出了一个问题,但它被关闭了。 A workaround is to go into node_modules and find the ES module build for firebaseui ( node_modules/firebaseui/dist/esm.js ), and change the first line from import * as firebase from 'firebase/app';一种解决方法是将 go 放入node_modules并找到为 firebaseui ( node_modules/firebaseui/dist/esm.js ) 构建的 ES 模块,并将第一行从import * as firebase from 'firebase/app'; to import firebase from 'firebase/app'; import firebase from 'firebase/app'; . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM