Why getting Uncaught TypeError: Failed to resolve module specifier "firebase". Relative references must start with either "/", "./", or "../"?
Why getting Uncaught TypeError: Failed to resolve module specifier "firebase". Relative references must start with either "/", "./", or "../"?
我已经将我的代码从 v8 版本转移到带有模块化代码的 v9 版本,但是尽管安装了汇总包,我还是收到了这个错误。
我的 JS 代码:
<script type="module">
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
import firebase from 'firebase';
import { initializeApp } from "firebase/app"
import { getAuth, onAuthStateChanged } from "firebase/auth";
import { getDatabase } from "firebase/database"
// Your web app's Firebase configuration
const firebaseConfig = {
//app config
};
// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);
const db = getDatabase(firebaseApp);
const auth = getAuth(firebaseApp);
</script>
我收到的错误:未捕获的类型错误:无法解析模块说明符“firebase”。相对引用必须以“/”、“./”或“../”开头。
我花了相当多的时间,但未能找到问题所在。
据我了解,firebase 9 的很大一部分是您不再需要导入整个 firebase,现在可以只导入您需要的任何模块。
因此您不需要
import firebase from 'firebase';
尝试不导入“firebase”,看看会发生什么
我也有类似的错误。我这样解决了这个错误。
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-app.js'
import { getAuth } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-auth.js'
我认为你可以使用那些 URL。
我不确定这是正确的方法。
我已经将我的代码从 v8 版本转移到带有模块化代码的 v9 版本,但是尽管安装了汇总包,我还是收到了这个错误。 我的 JS 代码:
<script type="module">
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
import firebase from 'firebase';
import { initializeApp } from "firebase/app"
import { getAuth, onAuthStateChanged } from "firebase/auth";
import { getDatabase } from "firebase/database"
// Your web app's Firebase configuration
const firebaseConfig = {
//app config
};
// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);
const db = getDatabase(firebaseApp);
const auth = getAuth(firebaseApp);
</script>
我收到的错误:未捕获的类型错误:无法解析模块说明符“firebase”。相对引用必须以“/”、“./”或“../”开头。
我花了相当多的时间,但未能找到问题所在。
据我了解,firebase 9 的很大一部分是您不再需要导入整个 firebase,现在可以只导入您需要的任何模块。
因此您不需要
import firebase from 'firebase';
尝试不导入“firebase”,看看会发生什么
我也有类似的错误。我这样解决了这个错误。
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-app.js'
import { getAuth } from 'https://www.gstatic.com/firebasejs/9.6.3/firebase-auth.js'
我认为你可以使用那些 URL。
我不确定这是正确的方法。