ES6导入和导出语法出现“意外令牌{”错误 [英] 'Unexpected Token {' error with ES6 Import and Export syntax

查看:82
本文介绍了ES6导入和导出语法出现“意外令牌{”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在2个javascript文件中使用布尔值(一个用于导出布尔值,另一个用于导入布尔值)。我对第一个文件使用 export isReady ('isReady'是布尔名称),并且对'./otherfile使用 import {isReady}。 js'; 在另一个文件上。它们仍然会给出相同的错误,通常位于 import 语法中。

I'm trying to use a boolean across 2 javascript files(one that exports the bool and one that imports it). I use export isReady('isReady' being the boolean name) for the first file, and I use import { isReady } from './otherfile.js'; on the other file. They still give the same error, usually lying in the import syntax.

推荐答案

我只需要在html < script> 元素中添加 type = module 。感谢@ zero298的评论。它带来了一些额外的错误,但是很容易解决。谢谢!

I just needed to add type="module" to the html <script> element. Thanks to @zero298 's comment. It gave a few extra errors, but they were easy to resolve. Thanks!

这篇关于ES6导入和导出语法出现“意外令牌{”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆