[Engineering development] Uncaught SyntaxError: Cannot use import statement outside a module introduced jQuery exception in vue


​Introducing jquery into reporting error 1 : Uncaught SyntaxError: Cannot use import statement outside a module
insert image description here**Reason: **In fact, the directory structure is very simple, that is, building the configuration of webpack from scratch, and introducing jquery files to report an error.

	<!-- 给script增加了一个属性 type="module" 看了一篇文章启发的,但是问题又来了,引发错误2。 -->
	<script type="module" src="./index.js"></script> 

Error 2:Uncaught TypeError: Failed to resolve module specifier "jquery". Relative references must start with either "/", "./", or "../".
insert image description here In fact, the key to the problem is not in this location, but because the index.js file I introduced is under the src directory, not the main.js file under dist.
Problem Solving: Introducing the index.js file under dist can solve this problem.

 <!-- type="module"属性是可以不要的。 -->
 <script type="module" src="../dist/main.js"></script>

Guess you like

Origin blog.csdn.net/YBJ2022/article/details/129304197