【问题标题】:VSCode IntelliSense for NativeScript Cannot Find Module 'ui/frame'NativeScript 的 VSCode IntelliSense 找不到模块“ui/frame”
【发布时间】:2017-10-12 19:08:43
【问题描述】:

我是 NativeScript 的新手,VSCode 和 TypeScript 定义的新手,并且在设置 VSCode 以通过 IntelliSense 对 tns-core-modules 所需的模块执行自动完成时遇到困难。

我的 package.json 中的依赖项:

"dependencies": {
    "lodash": "^4.17.4",
    "nativescript-theme-core": "1.0.4",
    "tns-core-modules": "3.2.0"
}

lodash 的 IntelliSense 可以按预期完美运行。但是,来自 tns-core-modules 的任何东西的 IntelliSense 都不起作用。

我从 NativeScript 的 Sidekick 中的空白模板创建了一个项目。谷歌搜索后,我添加了一个 jsconfig.json 如下:

{
    "compilerOptions": {
        "checkJs": true,
        "target": "ES6",
        "allowSyntheticDefaultImports": true
    },
    "include": [
        "app/**/*"
    ]
}

CheckJS 在 home-page.js 中显示此错误

将鼠标悬停在它读取的错误上:

[js] Cannot find module 'ui/frame'.

老实说,我尝试做各种我不理解的事情,例如:

/// <reference path="../../node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="../../node_modules/tns-core-modules/ui/frame/frame.d.ts"/>

我的理解是因为“ui/frame”不在package.json中,但是nativeScript会根据构建的平台智能地从tns-core-modules中提取出合适的模块...

最大的问题是:如何让 VSCode 了解正确的映射并在 ui/frame 和相应的“frame.d.ts”之间建立联系。

提前致谢!

编辑: 我想更新任何读者,让他们知道我不是也不想编写 TypeScript 代码,但我确实希望 VSCode 正确解释 typescript 定义。

【问题讨论】:

  • 会在 ui/frame 前面添加 tns-core-modules 吗?
  • @pkanev 不幸的是。我试过了,如果我对 nativescript 的理解是正确的,那就没有意义了。此外,如果您查看 frame.d.ts,它实际上定义了模块“ui/frame”。但是,我真的不知道打字稿。
  • 运行时检查ui/frame 是否是内置(tns-core-modules)模块,然后继续查看已安装的node_modules。前置tns-core-modules 只会解析为node_modules/tns-core-modules,所以没有错。
  • @pkanev 你是对的,它不会中断(因为在应用程序中仍然可以构建)但它仍然找不到模块,因为没有 tns-core-modules/ui/ frame/frame.js 或 index.js 让 npm 知道自动导入。我从 ui/frame 中的 package.json 获取 frame.js,因为它包含“main”:“frame”。它不会知道它应该使用 frame.ios.js 还是 frame.android.js,而且它似乎没有意识到它应该使用“frame.d.ts”作为类型。

标签: visual-studio-code intellisense nativescript


【解决方案1】:

这个问题的答案是使用 TypeScript。没有它我无法让它工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 2022-07-25
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    相关资源
    最近更新 更多