Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

324
Vistas
.ts is not imported into the react application, what should I do?

ERROR in ./src/store/store.ts 4:0-50 Module not found: Error: Can't resolve '../services/AuthService' in 'D:\DND\dnd1\src\store'

webpack compiled with 1 error and 4 warnings

I tried to import in different ways. But in any case, it does not work. The most important thing is that my react was originally a js project and I added it .ts files

import {IUser} from '../models/IUser'
import {makeAutoObservable} from 'mobx'
import AuthService from '../services/AuthService';
// const AuthService = require ('../services/AuthService.ts')

export default class Store {
    user = {} as IUser;
    isAuth = false;
    
    constructor(){
        makeAutoObservable(this)
    } 

    setAuth(bool: boolean){
        this.isAuth = bool
    }

    setUser(user: IUser){
        this.user = user
    }

    async login(email: string, password: string){
        try {
            const response = await AuthService.login(email, password)
            localStorage.setItem('token', response.data.accessToken)
            this.setUser(response.data.user)
        } catch (e) {
            console.log(e.response?.data?.message)
        }
    }

    async registration(email: string, password: string, name: string, lastname: string, surname: string){
        try {
            const response = await AuthService.registration(email, password, name, lastname, surname)
            localStorage.setItem('token', response.data.accessToken)
            this.setUser(response.data.user)
        } catch (e) {
            console.log(e.response?.data?.message)
        }
    }

    async logout(){
        try {
            const response = await AuthService.logout()
            localStorage.removeItem('token')
            this.setAuth(false)
            this.setUser({} as IUser)
        } catch (e) {
            console.log(e.response?.data?.message)
        }
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's difficult to pinpoint the exact problem without knowing what your webpack configuration looks like, but my guess is that you don't have a loader for TypeScript files set up. I recommend adding something like the following to your module.exports and seeing if that solves your issue:

module: {
  rules:[
    {
      test: /\.ts$/,
      use: 'ts-loader',
      include: [path.resolve(__dirname, 'src')]
    }
  ],
  resolve: {
    extensions: ['.ts', '.js'],
  },
},
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda