在vue中引入引入jquery报错,报错1:Uncaught SyntaxError: Cannot use import statement outside a module
**原因:**其实目录结构是非常简单,就是从头开始搭建webpack的配置,引入jquery文件报错。
<!-- 给script增加了一个属性 type="module" 看了一篇文章启发的,但是问题又来了,引发错误2。 -->
<script type="module" src="./index.js"></script>
报错2:Uncaught TypeError: Failed to resolve module specifier "jquery". Relative references must start with either "/", "./", or "../".
其实问题的关键不在这个位置,而是因为我引入的index.js文件是src目录下面的,而不是dist下面的main.js文件。
问题解决:引入dist下面的index.js文件就可以解决该问题。
<!-- type="module"属性是可以不要的。 -->
<script type="module" src="../dist/main.js"></script>