Cannot read properties of undefined (reading ‘uri‘)
Posted 陈希瑞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cannot read properties of undefined (reading ‘uri‘)相关的知识,希望对你有一定的参考价值。
Cannot read properties of undefined (reading ‘uri’)
问题描述
Cursor更新后遇到如标题那样的问题,我直接百度没发现解决方法,遂到github的issue看了看!
解决方法
有网友给了解决方法,如下图:
如果对你有帮助,可以留下一个赞吗?
TypeError: Cannot read properties of undefined (reading 'app') (Flutter web app)
【中文标题】TypeError: Cannot read properties of undefined (reading \'app\') (Flutter web app)【英文标题】:TypeError: Cannot read properties of undefined (reading 'app') (Flutter web app)TypeError: Cannot read properties of undefined (reading 'app') (Flutter web app) 【发布时间】:2021-12-11 21:07:18 【问题描述】:我尝试将我的网络应用程序连接到 Firestore 并尝试运行我的网络应用程序超过 3 天,但我不能。请帮助我解决我的问题并更快地发展我的创业公司。 显示如下错误:TypeError: Cannot read properties of undefined (reading 'app') 我该如何解决这个问题?
我的 Flutter (index.html) 代码崩溃了。
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="jaitun_admin">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<title>jaitun_admin</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.1/firebase-auth.js"></script>
<script>
const firebaseConfig =
apiKey: "AIzaSyDmv2oj8958mbUg07FW316IxOAiOdYhPTg",
authDomain: "jaituncustomaer.firebaseapp.com",
databaseURL: "https://jaituncustomaer-default-rtdb.firebaseio.com",
projectId: "jaituncustomaer",
storageBucket: "jaituncustomaer.appspot.com",
messagingSenderId: "771594380318",
appId: "1:771594380318:web:aa0a3b61483d19dc2bfa0f",
measurementId: "G-B064R6Q9GJ"
;
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs()
if (scriptLoaded)
return;
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
if ('serviceWorker' in navigator)
// Service workers are supported. Use them.
window.addEventListener('load', function ()
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) =>
function waitForActivation(serviceWorker)
serviceWorker.addEventListener('statechange', () =>
if (serviceWorker.state == 'activated')
console.log('Installed new service worker.');
loadMainDartJs();
);
if (!reg.active && (reg.installing || reg.waiting))
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion))
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
else
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
);
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() =>
if (!scriptLoaded)
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
, 4000);
);
else
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
</script>
</body>
</html>
【问题讨论】:
这是我的 pubspec.yml 版本:1.0.0+1 环境:sdk:">=2.3.0 cupertino_icons: ^1.0.2 firebase_core: ^1.3.0 cloud_firestore: ^2.2.2 ars_dialog: ^1.0.8 alert_dialog: ^1.0.0 firebase_auth: ^1.4.1 flutter_admin_scaffold: ^0.0.5 firebase: ^9.0.1 firebase_storage: ^8.1.3 chips_choice: ^2.0.1 flutter_switch: ^0.2.1 email_validator: ^1.0.6 Code samples 应该是minimal、完整和有代表性的。与问题相关的信息应编辑到问题中,而不是留在 cmets 中。 【参考方案1】:Sol.1
在 firebase 初始化时。 你想用什么作为你的公共目录?
使用 build/web 而不是 public 作为公共目录。
如果还是不行...
Sol.2
将 index.html 中的基本 href 链接 ($FLUTTER_BASE_HREF) 替换为存储库的位置。
<base href="$FLUTTER_BASE_HREF">
到 <base href="/">
或 <base href="/your-repository/">
右键单击并查看页面源以了解想法。
【讨论】:
以上是关于Cannot read properties of undefined (reading ‘uri‘)的主要内容,如果未能解决你的问题,请参考以下文章
Cannot read properties of undefined (reading 'length')
Cannot read property 'replace' of undefined
TypeError: Cannot read property ‘url‘ of undefined
vue添加组件报错 Cannot read properties of undefined (reading ‘toLowerCase‘)
Uncaught TypeError: Cannot read properties of undefined (reading ‘Constructo