TypeError:无法读取未定义的属性“instanceIdentifier”(FirebaseStorage)

Posted

技术标签:

【中文标题】TypeError:无法读取未定义的属性“instanceIdentifier”(FirebaseStorage)【英文标题】:TypeError: Cannot read property 'instanceIdentifier' of undefined (FirebaseStorage) 【发布时间】:2021-07-11 13:24:29 【问题描述】:

我正在尝试使用 dart web 将一些文件上传到 Firebase Storage。但是引用的声明失败了。这里是声明引用时的代码:

Reference storageReference = FirebaseStorage.instance.ref().child('test');   

index.html

<script src="https://www.gstatic.com/firebasejs/8.3.1/firebase-storage.js"></script>

pubspec.yaml:

dependencies:
    firebase_storage: ^8.0.3

最后这是错误:

TypeError: Cannot read property 'instanceIdentifier' of undefined
at _.ft [as instanceFactory] (https://www.gstatic.com/firebasejs/8.3.1/firebase-storage.js:1:39384)
at I.getOrInitializeService (https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js:1:8586)
at I.getImmediate (https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js:1:6577)
at G._getService (https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js:1:14805)
at G.n.type.a.<computed> [as storage] (https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js:1:17592)
at Object.e [as storage] (https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js:1:17415)
at Object.getStorageInstance (http://localhost:36593/packages/firebase_storage_web/src/interop/storage.dart.lib.js:777:75)
at new firebase_storage_web.FirebaseStorageWeb.new (http://localhost:36593/packages/firebase_storage_web/src/reference_web.dart.lib.js:321:33)
at firebase_storage_web.FirebaseStorageWeb._nullInstance.delegateFor (http://localhost:36593/packages/firebase_storage_web/src/reference_web.dart.lib.js:267:14)
at Function.instanceFor (http://localhost:36593/packages/firebase_storage_platform_interface/src/platform_interface/platform_interface_task_snapshot.dart.lib.js:970:83)
at firebase_storage.FirebaseStorage.__.get [_delegate] (http://localhost:36593/packages/firebase_storage/firebase_storage.dart.lib.js:95:120)
at firebase_storage.FirebaseStorage.__.ref (http://localhost:36593/packages/firebase_storage/firebase_storage.dart.lib.js:135:58)
at add_connector._AddConnectorState.new.onPressedSendButton (http://localhost:36593/packages/client_doc_collector/screens/home/main_section/connectors/add_connector/add_connector.dart.lib.js:1000:76)
at onPressedSendButton.next (<anonymous>)
at runBody (http://localhost:36593/dart_sdk.js:39051:34)
at Object._async [as async] (http://localhost:36593/dart_sdk.js:39082:7)
at add_connector._AddConnectorState.new.onPressedSendButton (http://localhost:36593/packages/client_doc_collector/screens/home/main_section/connectors/add_connector/add_connector.dart.lib.js:996:20)
at ink_well._InkResponseState.new.[_handleTap] (http://localhost:36593/packages/flutter/src/material/icon_button.dart.lib.js:50511:42)
at tap.TapGestureRecognizer.new.invokeCallback (http://localhost:36593/packages/flutter/src/gestures/recognizer.dart.lib.js:203:18)
at tap.TapGestureRecognizer.new.handleTapUp (http://localhost:36593/packages/flutter/src/gestures/tap.dart.lib.js:417:40)
at tap.TapGestureRecognizer.new.[_checkUp] (http://localhost:36593/packages/flutter/src/gestures/tap.dart.lib.js:223:12)
at tap.TapGestureRecognizer.new.acceptGesture (http://localhost:36593/packages/flutter/src/gestures/tap.dart.lib.js:199:23)
at arena.GestureArenaManager.new.sweep (http://localhost:36593/packages/flutter/src/gestures/arena.dart.lib.js:222:31)
at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:36593/packages/flutter/src/gestures/binding.dart.lib.js:335:27)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:36593/packages/flutter/src/gestures/binding.dart.lib.js:314:24)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:36593/packages/flutter/src/rendering/layer.dart.lib.js:6087:13)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerEventImmediately] (http://localhost:36593/packages/flutter/src/gestures/binding.dart.lib.js:285:14)
at binding$5.WidgetsFlutterBinding.new.handlePointerEvent (http://localhost:36593/packages/flutter/src/gestures/binding.dart.lib.js:258:43)
at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:36593/packages/flutter/src/gestures/binding.dart.lib.js:247:14)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:36593/packages/flutter/src/gestures/binding.dart.lib.js:237:65)
at Object.invoke1 (http://localhost:36593/dart_sdk.js:183786:7)
at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (http://localhost:36593/dart_sdk.js:164268:15)
at _engine.PointerBinding.__.[_onPointerData] (http://localhost:36593/dart_sdk.js:164902:49)
at http://localhost:36593/dart_sdk.js:165359:28
at http://localhost:36593/dart_sdk.js:165312:16
at http://localhost:36593/dart_sdk.js:165006:11


    

【问题讨论】:

【参考方案1】:

我正在使用这个 Firebase 资源 v8.3.1:

<script src="https://www.gstatic.com/firebasejs/8.3.1/firebase-storage.js"></script>

我在尝试使用 firebase 存储 SDK 时遇到了同样的错误:

Uncaught TypeError: Cannot read property 'instanceIdentifier' of undefined 

我将firebase存储脚本资源版本改为8.1.2:

<script src="https://www.gstatic.com/firebasejs/8.1.2/firebase-storage.js"></script>

现在,错误不再出现。

我的建议是: 如果您没有其他依赖项,请尝试将 Firebase 存储 SDK 的 8.3.1 更改为 8.1.2 版本。为我工作...

【讨论】:

【参考方案2】:

...instance.ref()中需要引用路径

查看官方flutterfire storage reference docs。

【讨论】:

以上是关于TypeError:无法读取未定义的属性“instanceIdentifier”(FirebaseStorage)的主要内容,如果未能解决你的问题,请参考以下文章

TypeError:无法读取未定义的属性“findAll”(expressjs)

TypeError:无法读取未定义的属性(读取“问题”)

TypeError:无法读取未定义的属性“babel”

TypeError:无法读取未定义的属性(读取“匹配”):

TypeError:无法读取未定义的属性“存在”

TypeError:无法在 gitlab 中读取未定义的属性(读取“读取”)