语法错误:意外的标识符'TypeIt'。导入调用只需要一个参数

时间:2018-07-22 02:08:38

标签: javascript html import

我正在创建我的第一个网站,并且尝试使用type it库。但是,每当我尝试将其导入到脚本文件中时,都会出现上述错误。到目前为止,这是我的代码:

Index.html文件:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
   <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
  <span id="element">Here is a string.</span>
</body>
<script src="script.js"></script>
</html>

script.js文件:

import TypeIt from 'typeit';

var instance = new TypeIt('#element', {
    strings: ['This is my string!']
});

这是文件夹结构:

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您不使用任何模块捆绑器,则需要在html文件之前添加以下标记:

    <script src="/node_modules/typeit/dist/typeit.min.js"></script>

此外,删除script.js文件中的import语句,并确保在加载script.js文件之前先加载typeit.min.js。