简体   繁体   English

无法在 Vue.js 应用程序的 main.ts 中导入打字稿模块

[英]Cannot import typescript modules inside main.ts on Vue.js app

I am building a simple vue.js app using typescript,I am trying to do some routing and bring the route file to main.ts but when I run the app I get the following error:我正在使用打字稿构建一个简单的 vue.js 应用程序,我正在尝试进行一些路由并将路由文件带到main.ts但是当我运行该应用程序时出现以下错误:

These relative modules were not found:

* ./plugins/vuetify in ./src/main.ts
* ./router/routerIndex in ./src/main.ts
* ./store/index in ./src/main.ts

main.ts is in src/main.ts main.tssrc/main.ts

indexRouter.ts is in src/router/indexRoute.ts indexRouter.tssrc/router/indexRoute.ts


main.ts主文件

import Vue from 'vue';
import vuetify from "./plugins/vuetify";
import App from "./App.vue"
import store from "./store/index";
import VueRouter from 'vue-router'
import router from "./router/routerIndex"


Vue.config.productionTip = false

Vue.use(VueRouter);

new Vue({
  store,
  vuetify,
  render: h => h(App),
  router
}).$mount("#app");

routerIndex.ts路由器索引.ts

import Vue from "vue";
import Router from "vue-router";
import Home from "../components/pages/Home.vue";


Vue.use(Router);

const routes = [
    {
        name: "home",
        path: "/",
        component: Home
    }
]

const router = new Router({ mode: "history", routes });

export default router;

tsconfig.json配置文件

{
  "compilerOptions": {
  "target": "ES2019",                          
  "module": "commonjs",
  "outDir": "./dist",
  "strict": true,
  "esModuleInterop": true,
  "sourceMap": true,
  "experimentalDecorators": true,
  "forceConsistentCasingInFileNames": true
 },
"include": [
      "src/**/*",
      "src/**/*.ts",
      "src/**/*.tsx",
      "src/**/*.vue",
      "tests/**/*.ts",
      "tests/**/*.tsx"
    ],

}

This project was not installed with Vue@Cli, it was installed with npm by the person who created the project.这个项目不是用 Vue@Cli 安装的,它是由创建项目的人用 npm 安装的。

I am new to both Vue and Typescript so I might be screwing up something.我是VueTypescript所以我可能会Typescript一些事情。

Thanks in advance.提前致谢。

You can install @vue/cli, then open the vue ui , import the your project in the vue ui and then using the ui again download typescript plugin.您可以安装@vue/cli,然后打开vue ui ,在vue ui中导入您的项目,然后再次使用ui 下载typescript 插件。 Tell me if anything is unclear:)如果有什么不清楚的请告诉我:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vue 3 TypeScript - `main.ts` 和测试中的 `App.vue` 问题 - Vue 3 TypeScript - Problem with `App.vue` in `main.ts` and Tests 在main.ts(typescript)中的一个函数中加载外部javascript函数 - Load external javascript functions in one function inside main.ts (typescript) 尝试在 Django 应用程序的 js 文件中导入 vue.js 时出现“未捕获的语法错误:无法在模块外使用导入语句” - “Uncaught SyntaxError: Cannot use import statement outside a module” when trying to import vue.js inside js file in Django app 无法通过动态导入访问 object 属性。 Vue.js + ts - Cannot access object properties from dynamic import. Vue.js + ts EmailJS - Vue.js 2 和 TS - EmailJS - Vue.js 2 and TS ./src/main.ts - 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/node_modules/@ngtools/webpack/src/ivy/index.js): - ./src/main.ts - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/node_modules/@ngtools/webpack/src/ivy/index.js): Vue.js 从组件中的 App.vue 导入数组 - Vue.js import Array from App.vue in Component JS导入内部的Vue.js异步更新 - Vue.js async update from inside JS import Vue.js 导入mixin 不导入app - Vue.js Import mixin does not import in app 无法获取 Vue 状态的元素 (Vue.js/JS/TS) - Cannot get Vue state's element (Vue.js/JS/TS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM