【问题标题】:How to make atom-typescript recognize modules without relative path?如何让 atom-typescript 识别没有相对路径的模块?
【发布时间】:2015-11-27 20:32:01
【问题描述】:

我正在关注angular-meteor tutorial using angular2 and typescript

由于我使用的是 atom,因此我添加了 atom-typescript 包和一个 tsconfig 文件以利用类型声明文件。

我正在尝试让 atom-typescript 识别 client/parties-form/parties_form.ts 上的导入:

import {Parties} from  'collections/parties';

但是 atom 给我以下错误:Cannot find module 'collections/parties'.

当我使用相对路径导入模块时出现错误:

import {Parties} from '../../collections/parties';

但随后流星无法编译并给我一个Path reservation conflict 错误。

我希望能够在没有 atom-typescript 给我任何错误的情况下使用第一种导入,从而识别我的类型声明文件。我错过了什么?

我的tsconfig.json 文件:

{
    "version": "1.5.0",
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false,
        "emitDecoratorMetadata": true
    },
    "filesGlob": [
        "./**/*.ts",
        "!./typings/**/*.ts"
    ]
}

完整版教程代码可以在here找到。

【问题讨论】:

    标签: typescript angular atom-editor angular-meteor tsconfig


    【解决方案1】:

    import {Parties} from '../../collections/parties';

    此要求并非特定于 atom-typescript。 TypeScript 不支持 您自己在 node_modules 之外的代码 的非相对路径。跟踪此问题以获取详细信息:https://github.com/Microsoft/TypeScript/issues/5039

    【讨论】:

    • 我有 webpack 处理导入,有没有办法抑制 atom 中的错误消息(我的应用程序运行完美,所以它不是真正的错误)
    • 在编译器设置中使用 TypeScript 的“baseUrl”选项。因此,例如,如果您的代码位于 src "baseUrl": "./src"
    • 糟糕!还需要加"rootDirs": ["./src"]
    猜你喜欢
    • 2017-05-04
    • 2011-05-01
    • 2021-08-10
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多