问题描述:

现有两个文件:

profile.js

  1. const firstName = 'Michael';
  2. const lastName = 'Jackson';
  3. const year = 2018;
  4. export {firstName, lastName, year}

test.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <script>
  9. import {firstName, lastName, year} from './profile.js';
  10. console.log(firstName);
  11. console.log(lastName);
  12. console.log(year);
  13. </script>
  14. </body>
  15. </html>

运行结果:

test.html:9 Uncaught SyntaxError: Unexpected token {

问题解答:

在HTML文件中不能使用export,import,需要在webpack构建项目中使用,并且只作用于.vue.js文件。

如果非要使用且浏览器支持ES6,需要加上 type="module"

  1. <script type="module">
  2. import {firstName, lastName, year} from './profile.js';
  3. console.log(firstName);
  4. console.log(lastName);
  5. console.log(year);
  6. </script>

ES6 export,import报错的更多相关文章

  1. 用js中的let等操作,要手动开启ECMAScript6(如果不设置,let等ES6语法会报错)

    问题:idea默认没有开启ECMAScript6,需要进行设置:(如果不设置,let等ES6语法会报错)步骤: File | Settings | Languages & Frameworks ...

  2. es6 import 报错

    现在绝大多数的浏览器都不支持ES6,所以使用es6时需要使用bebal把es6转化为es5, 项目目录: demo1:单个js文件的转化 src文件下的 test1.js const aa=" ...

  3. es6编写generator报错

    首先babel基础包(不安装额外东西)并不是支持完整的es6语言 自己写的如下代码 let generator = function* () { ; ,,]; ; }; var gen = gener ...

  4. vue +ts 在router的路由中import报错的解决方案

    在router.ts中引入.vue文件,会提示打不到module,但是编译可能成功,运行也不报错 找了好久,发现了这个答案 https://segmentfault.com/a/11900000167 ...

  5. 关于使用spring版本4.1.6注解@Import报错

    记录一下遇到的错误 org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 使用环境:spring 4.1. ...

  6. matplotlib.pyplot import报错: ValueError: _getfullpathname: embedded null character in path

    Environment: Windows 10, Anaconda 3.6 matplotlib 2.0 import matplotlib.pyplot 报错: ValueError: _getfu ...

  7. Eclipse + Pydev开发Python时import报错解决方法

    一.  原文链接:http://blog.csdn.net/lhanchao/article/details/51306626            用eclipse +PyDev开发python时, ...

  8. ImportError: DLL load failed: 找不到指定的模块;ImportError: numpy.core.multiarray failed to import 报错解决

    python程序运行出错,出错的两行主要信息如下: ImportError: DLL load failed: 找不到指定的模块 ImportError: numpy.core.multiarray ...

  9. Windows下通过pip安装PyTorch 0.4.0 import报错

    问题:通过pip安装PyTorch 0.4.0成功,但是import时报错. import torch  File "D:\Python\Python36\lib\site-packages ...

随机推荐

  1. cross entropy与logistic regression

    维基上corss entropy的一部分 知乎上也有一个类似问题:https://www.zhihu.com/question/36307214 cross entropy有二分类和多分类的形式,分别 ...

  2. sudo: Sorry, you must have a tty to run

    The requiretty option in sudoers file The requiretty if set in sudo config file sudoers, sudo will o ...

  3. WPF学习笔记(7):DataGrid中数字自定义格式显示

    DataGrid中数据显示如下图,数据格式比较杂乱.希望达到以下要求:(1)所有数据保留两位小数:(2)超过1000的数字显示千分位:(3)如果数据为0,不显示. 首先想到用StringFormat进 ...

  4. Mysql索引学习笔记

    1.btree索引与hash索引 下列范围查询适用于 btree索引和hash索引: SELECT * FROM t1 WHERE key_col = 1 OR key_col IN (15,18,2 ...

  5. 【办公-Word-VB】人民币大写转换-带完整注释

    完整代码见:我的CSDN博客 -------------------- 应公司财务人员的请求,需在Word中做个:输入阿拉伯数字,自动转换成大写,并填充到Word控件中对应的亿.万.千控件格子的功能, ...

  6. o'Reill的SVG精髓(第二版)学习笔记——第七章

    第七章:路径 所有描述轮廓的数据都放在<path>元素的d属性中(d是data的缩写).路径数据包括单个字符的命令,比如M表示moveto,L表示lineto.接着是该命令的坐标信息. 7 ...

  7. Beginning DirectX11 Game Programming

    DirectX11 or 10 made a big change comparing to DirectX9 The fixed-function pipeline was removed in D ...

  8. 打包上传appsto错误 ERROR ITMS-90087: 和WARNING ITMS-90080: 问题

    第一个错误 (Hyphenate.framework可以看粗是环信问题) ERROR ITMS-90087: "Unsupported Architectures. The executab ...

  9. spring入门学习感悟

    1:ioc:控制反转 控制权的转移,应用程序本身不负责依赖对象的创建和维护,而是有外部容器负责创建和维护的(获取依赖对象的过程被反转了) 2:di:依赖注入,它是一种控制反转的一种实现方法,ioc容器 ...

  10. djano-模板层基础知识

    ########模板层######## 模板层其实就是templates文件夹里的html文件 其实这里的每个html不是真正意义的上html代码,只有经过模板渲染过后才算的上真正的html页面. 一 ...