我有一个HTML文件:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<!-- Importing jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Importing Firebase-->
<script src="https://www.gstatic.com/firebasejs/5.9.2/firebase.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Web-Loc</title>
</head>
<body>
<script src="main.js"></script>
<script type="module" src="database.js"></script>
</body>
</html>
我的main.js
文件是:
import * as database from 'database.js';
export async function main(){
database.loadFirebase();
}
main();
我的database.js
文件是:
export function getAPIKeyFrom(url){
return new Promise((resolve,reject) => {
$.getJSON(url, response => {
resolve(response.apikey)
})
})
}
export async function loadFirebase(){
// Initialize Firebase
var config = {
apiKey: getAPIKeyFrom("keys.json"),
authDomain: "something.here.com",
databaseURL: "https://something.here.com",
projectId: "somethinghere",
storageBucket: "something.appspot.com",
messagingSenderId: "328363099410"
};
firebase.initializeApp(config);
}
但是当我尝试执行此代码时,出现以下错误:
未捕获的SyntaxError:意外令牌*
正如您在HTML文件中看到的那样,我以模块方式声明了database.js
,我试图在Chrome上执行此操作,但我的版本是63。我已经在Chrome 73上尝试过很好,并且我遇到了同样的错误,因此浏览器不是问题,我进行了大量搜索,但仍未找到解决该问题的方法。