![](/img/trans.png)
[英]Here, I am trying to login using firebase auth, but getting 400 error. I am giving exact email & password but it's showing below error
[英]I am trying to use import and export in javascript but it is showing uncaught error. Here is the code :
我的代碼:
const person = {
name: 'Aish',
age:21,
}
export default person;
error : Uncaught SyntaxError: Unexpected token 'export' (at main.js:6:1)
將腳本擴展名更改為 .mjs,或將條目添加到package.json : "type": "module"
。
*Node.js 完全支持當前指定的 ECMAScript 模塊,並提供它們與其原始模塊格式 CommonJS 之間的互操作性。
啟用#
Node.js 有兩個模塊系統:CommonJS 模塊和 ECMAScript 模塊。作者可以通過 .mjs 文件擴展名、package.json“類型”字段或 --input-type 標志告訴 Node.js 使用 ECMAScript 模塊加載器。 在這些情況之外,Node.js 將使用 CommonJS 模塊加載器。 有關詳細信息,請參閱確定模塊系統。**
這是因為您正在使用 ES6 導入/導出,但您正在處理的環境正在使用 commonjs
對於Node.js
go 到您的 package.json 並將type
條目設置為"module"
例子:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
...
}
注意:確保將您的 nodejs 更新到最新版本
對於瀏覽器
在你的腳本標簽中添加type='module'
作為屬性
例子:
<script src="./index.js" type="module" defer></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.