首页 > 其他分享 >vite+vue3 遇到报错 Uncaught SyntaxError: Cannot use import statement outside a module (at main.js:1:1)

vite+vue3 遇到报错 Uncaught SyntaxError: Cannot use import statement outside a module (at main.js:1:1)

时间:2024-03-04 17:44:05浏览次数:227  
标签:use App module 报错 import app vite

按照报错找到了对应的位置

import { createApp } from '/node_modules/.vite/deps/vue.js?v=d0a669cf'
import App from '/src/pages/project1/App.vue'
// import './index.css'
// import router from "./router"

// createApp(App).mount('#app')

const app = createApp(App)

// app.use(router)

app.mount('#app')

应该就是第一句, 但是怎么都找不到错误的原因

直到翻到一个答案 

 

HTML 网页中,浏览器通过 script 标签加载 JavaScript 脚本。由于浏览器脚本的默认语言是 JavaScript,因此type="application/javascript"可以省略。在报错中了解到,
是说无法在模块外部使用import语句,因为Module 的加载实现的是es6语法,所以在浏览器加载html文件时,需要在script 标签中加入type="module"属性。

  

 

标签:use,App,module,报错,import,app,vite
From: https://www.cnblogs.com/dontbealarmedimwithyou/p/18052250

相关文章

  • 关于SAP-APP机器-R3trans -d报错-R3trans: /lib64/libstdc++.so.6: version `GLIBCXX_
    在SAP-应用-APP-机器上执行如下命令报错awpxxx03:prdadm270>R3trans-dR3trans:/lib64/libstdc++.so.6:version`GLIBCXX_3.4.26'notfound(requiredbyR3trans) 其实之前,使用过一种方法解决这个问题,可以参考笔者另一篇文章《关于Redhat-Linux中-compat-sap-c++的说......
  • pip install selenium报错 raise ReadTimeoutError--解决方法
    pipinstallselenium报错如下:raiseReadTimeoutError(self._pool,None,"Readtimedout.")pip._vendor.urllib3.exceptions.ReadTimeoutError:HTTPSConnectionPool(host='files.pythonhosted.org',port=443):Readtimedout. 原因:timeout超时,默认15s解......
  • nacos报错
    1.nacos日志报错com.alibaba.nacos.api.exception.runtime.NacosRuntimeException:ErrCode:500,ErrMsg:Userlimitofinotifywatchesreached解决:这个错误是由于Linux中inotify观察者数量达到上限导致的。在Linux系统中,inotify是用来监视文件系统事件的机制,当监视的文......
  • JSON.parse解析字符串报错-SyntaxError: Unexpected token ‘ in JSON at position 报
    “SyntaxError:Unexpectedtoken’inJSONatposition”报错原因是因为解析的字符串对象中,JSON.parse无法识别;JSON.parse可以将标准的json类型数据转换为JavaScript对象,如果数据不是正确的json类型的数据则会控制台报错,可能会阻断代码的正常运行我们可以写一个函数来......
  • shell工具连接linux时的报错问题
    问题描述在使用shell工具连接linux时报以下错误SSH!Agentauthselected,butnorunningagentisdetectedSSH!Agentauthselected,butnorunningagentisdetected解决方法方法1#首先使用ping方法查看是否在同一网段pingxxx.xxx.xx.x方法2#安装[openss......
  • 使用gradio启动web-ui时出现cannot import name 'RootModel' from 'pydantic'
    使用gradio启动web-ui时出现cannotimportname'RootModel'from'pydantic'出现该报错的原因:pydantic版本与gradio版本不对应。例:我使用的pydantic版本为1.10.14,报错时gradio的版本是最新版4.19.2。找到gradiogithub源码中的requirements.txt:aiofiles>=22.0,<24.0altair>=......
  • Import 相对导入中遇到的问题总结
    这是我写的第一遍博客,晚上6点52,有点困,大概写一下。一、包(Package)、模块(Modules)、脚本(Script)搞清楚什么是包、什么是模块、什么是脚本很重要,简单来说:Script是用来运行的,也就是"__name__"=="__main__"成立的.py文件Modules是一大堆Classfuntion的合集,我们不希望它的"__n......
  • pytorch报错:Variable._execution_engine.run_backward( # Calls into the C++ engine
    GPU模式下运行pytorch代码报错,pytorch为2.2.1,NVIDIA驱动版本535.161.07File"/home/devil/anaconda3/envs/sample-factory/lib/python3.11/site-packages/torch/_tensor.py",line522,inbackwardtorch.autograd.backward(File"/home/devil/anaconda3/envs/sample-......
  • 解决ssh链接报错问题
    在使用ssh连接时出现报错,如下┌──(kali㉿kali)-[~]└─[email protected]:nomatchinghostkeytypefound.Theiroffer:ssh-rsa,ssh-dss意思就是找不到匹配的主机密钥类型,需要手动......
  • Linux_Centos_yum报错总结
    ​此篇适用于yum报错【尝试其他镜像】并且【curl外网】不通的情况,此时一般考虑是网络的问题一,出现的报错信息: 此时测试curl/pingwww.baidu.com会发现无法连通 二,解决方法:1,首先查看dns的配置文件/etc/resolv.conf检查这里的nameserver这里有时候会因为第二个网卡......