vue使用中网页报错Failed to resolve module specifier “vue“. Relative references must start with either “/“

问题

初次使用vue框架用,在vscode中选择打开html文件查看页面时报错

原因

这是因为你的项目在不同的开发服务器上运行。

  • 通过 http://127.0.0.1:5501 访问的是一个本地服务器,通常是一些 IDE 或者本地服务器插件提供的。
  • 通过 http://localhost:5173 访问的是 Vite 开发服务器。

这两者之间的端口和地址可能不同,因为它们是不同的服务器实例。通常,你应该使用 Vite 提供的服务器地址 http://localhost:5173 来访问你的 Vue 项目。

在终端中,当你运行 npx vite 启动 Vite 开发服务器时,终端会输出一个 URL,通常是 http://localhost:xxxx,其中 xxxx 是分配给 Vite 服务器的端口号。你应该使用这个地址来访问你的应用程序,而不是使用其他可能由 IDE 或本地服务器插件提供的地址。

如果你使用的是 Visual Studio Code,那么在左下角可能有一个 "Go Live" 的按钮,它会启动一个本地服务器,提供类似 http://127.0.0.1:5501 这样的地址。但是,在 Vite 项目中,你通常应该使用由 Vite 提供的地址。

解决方法

不要直接通过IDE打开,通过启动vue项目给出的地址打开

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
引用[1]:Not using node.js : Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../" - 卑面派对 - 博客园 引用[2]:错误信息 Uncaught TypeError: Failed to resolve module specifier “three”. Relative references must start with either “/”, “./”, or “…/”. 引用[3]:html <head> <script type="importmap"> { "imports": { "three": "https://unpkg.com/three@0.138.0/build/three.module.js", "OrbitControls": "https://unpkg.com/three@0.138.0/examples/jsm/controls/OrbitControls.js" } } </script> </head> <body> <script type="module" src="js/test.js"></script> </body> // test.js import * as THREE from 'three'; import { OrbitControls } from 'OrbitControls'; scene = new THREE.Scene(); renderer = new THREE.WebGLRenderer(); controls = new OrbitControls(camera, renderer.domElement);。 问题:新建工程 Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../". 回答: 根据你提供的引用内容,错误信息"Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../"通常是由于模块的路径引用错误导致的。在你的新建工程,你可能没有正确引入Vue模块。请确保你已经正确安装了Vue,并在你的代码使用正确的路径引用Vue模块。你可以尝试使用相对路径或绝对路径来引用Vue模块,例如"./vue"或"/vue"。如果问题仍然存在,请检查你的引用路径是否正确,并确保你的Vue模块已经正确安装。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值