找不到模块“src/app/services/session.response”或其相应的类型声明

aag*_*raf 8 angular ngxs

我已将我的项目 Angular 上传到 Stackblitz,该项目在 Visual Studio Code 上完美运行。

但是,当我在 Stackblitz 上打开该项目时,出现一条错误消息:

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

我打开了session.action.ts文件:

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

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

我不明白问题出在哪里,因为我在 Visual Studio Code 上有相同的代码。

我在 Stackblitz 上的项目在这里

非常感谢您的帮助。

Pan*_*kos 17

不要使用绝对路径,因为 from "src/app/services/session.response";打字稿会尝试定位模块,这与您如何配置打字稿有很大关系tsconfig.json

对于属于当前项目的组件,您应该使用相对于项目路径的路径。在你的项目中检查一下,你会发现错误将被消除

import { SessionReponse } from '../../services/session.response';
Run Code Online (Sandbox Code Playgroud)

绝对路径被识别为应该存在于node_modules/.