Cannot find module 'src/app/services/session.response' or its corresponding type declarations
Asked Answered
G

2

10

I have upload my project Angular on Stackblitz, the project works perfectly on Visual Studio Code.

But, when I open the project on Stackblitz, I have an error message:

Error in src/app/store/session/session.actions.ts (1:32)
Cannot find module 'src/app/services/session.response' or its corresponding type declarations.

I opened the session.action.ts file:

import { SessionReponse } from "src/app/services/session.response";

export class SessionAction {
    static readonly type = '[login] connexion';
    constructor(public session: SessionReponse ) { }
}

I don't understand where comes the problem, because I have the same code on Visual Studio Code.

My project on Stackblitz is here.

Thanks you very much for your help.

Garganey answered 29/12, 2021 at 19:44 Comment(0)
J
19

Don't use absolute paths like from "src/app/services/session.response"; as typescript will try to locate a module, which has much to do with how you have typescript configured in tsconfig.json

You should use relative to your project paths for components that belong to the current project. Check this in your project and you will see that the error will be eliminated

import { SessionReponse } from '../../services/session.response';

Absolute paths are recognized as modules which should exist under node_modules/.

Jedlicka answered 29/12, 2021 at 21:53 Comment(0)
O
2

review your tsconfig.json configuration, need add "baseUrl": "./"into compilerOptions": {}

example:

"compilerOptions": {
    "baseUrl": "./",
    .... 
}
Oscine answered 8/12, 2023 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.