首页 > 解决方案 > 错误 编译失败,出现 1 个错误 未找到此依赖项:

问题描述

当我尝试导入此目录 services/AuthenticationService 中的另一个 javascript 文件时,我在 vue 组件中遇到错误

Module not found: Error: Can't resolve '@/services/AuthenticationService' 要安装它,您可以运行: npm install --save @/services/AuthenticationService

我一直在寻找解决此问题的方法,但找不到任何东西。任何帮助,将不胜感激

这是我的视图组件 register.vue

<template>
  <div>
<h1>Register</h1>
     <input type="email" name="email" v-model ="email" placeholder="email"> <br>
     <input type="password" name="password" v-model ="password" placeholder="password"> <br>
      <button @click="register">
      Register
    </button>
  </div>
</template>

<script>
import AuthenticationService from '@/services/AuthenticationService'
export default {
  data () {
    return {
      email: '',
      password: ''
    }
  },

  methods: {
  async register(){
  const response = await AuthenticationService.register({
        email: this.email,
        password: this.password
      })
  console.log(response.data)
    }
  }
}
</script>

<style scoped></style>

标签: javascriptvue.jswebpack-dev-server

解决方案


你的 webpack 配置中有解决方案吗?

resolve: {
  alias: {
    '@': path.resolve('path/to/your/source/folder')
  }
}

文档https://webpack.js.org/configuration/resolve/


推荐阅读