【问题标题】:Internal server error: Failed to resolve import "./store" from "src\main.ts". Does the file exist?内部服务器错误:无法从 \"src\\main.ts\" 解析导入 \"./store\"。文件是否存在?
【发布时间】:2022-08-20 06:39:48
【问题描述】:

我在我的应用程序中使用 vite,但在提供应用程序时遇到错误

内部服务器错误:无法从 \"src\\main.ts\" 解析导入 \"./store\"。文件是否存在?

代码是:

import store from \"./store\";

当我将代码更改为时,错误解决了

import store from \"@/store\";

以 ../ 开头的路径也一样

无法解析从 \"src\\views\\Main.vue\" 导入 \"../utils/directives/ClickOutSide\"。文件是否存在?

我的项目结构:

-src
  -- store
     -- index.ts
  -- router
     -- index.ts
  -- main.ts
  • 出色地,该文件存在于指定位置(即与main.ts 在同一文件夹中)?
  • 是的,都在同一个文件夹(src文件夹)中,它在webpack中工作,但在vite中没有
  • 您能否添加文件夹结构的屏幕截图以及这些导入语句位于哪些文件中?
  • @cSharp 我编辑了帖子并添加了项目结构
  • 我假设你正在从main.tsimport store from \"./store\"。如果你import store from \"./store/index.ts\" 会发生什么?

标签: vue.js vite


【解决方案1】:

我解决了我的问题,问题是我写了 extensions: [".vue"] 所以 我将其更改为扩展名:[".vue", ".ts", ".js"]

【讨论】:

    【解决方案2】:

    尝试将 ./ 替换为写入完整路径,如 resources/store.vue

    【讨论】:

      猜你喜欢
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2013-09-25
      • 2022-10-17
      • 2018-06-12
      • 1970-01-01
      • 2022-11-30
      相关资源
      最近更新 更多