未捕获到的SyntaxError:导入语句中出现意外的令牌{ [英] Uncaught SyntaxError: Unexpected token { in import statement

查看:209
本文介绍了未捕获到的SyntaxError:导入语句中出现意外的令牌{的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的第一个全栈应用程序放在一起,并且遇到了意外的语法错误:

I'm attempting to put my first full-stack application together and am getting an unexpected syntax error:

未捕获到的SyntaxError:意外令牌{"

"Uncaught SyntaxError: Unexpected token {"

错误来自我的map.js文件中的以下代码行:

The error is coming from this line of code in my map.js file:

import {userInput} from './algorithm/searchingAlgorithm.js';

ejs文件:

<head>
    <script type="text/javascript" src="../javascripts/map.js"></script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCx0LvEwPUgGhpLjCErr24dOnk-VWjo83g&callback=initMap">
    </script>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>

来自"./algorithm/searchingAlgorithm.js":

from './algorithm/searchingAlgorithm.js':

export default async function userInput(origin, destination){

我已经做了很多搜索,但还没有找到答案.我正在使用node.js/express和express生成器javascript.我也在利用Google Maps API.

I've done a lot of searching and have yet to come up with an answer. I'm using node.js/express and express generator, javascript. I'm also utilizing the google maps api.

推荐答案

importexport语句在Web开发中经常使用,但由于它们是JavaScript语言.您需要将代码构建"为浏览器可以执行的格式.网络上的示例代码倾向于假定您已经在执行此操作.

The import and export statements are used frequently in web development, but they do not currently work automatically in a browser because they are newer features in the JavaScript language. You need to "build" the code into a format that the browser can execute. Example code on the web tends to assume that you are already doing this.

有多种工具可让您执行此操作,例如汇总

There are different tools that allow you to do this, such as Rollup or Webpack.

这篇关于未捕获到的SyntaxError:导入语句中出现意外的令牌{的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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