2

I have a Nativescript code sharing project. Modules in files with tns.ts extension cannot be resolved by typescript. I get the following message. I think this happens because all tns.ts, android.ts and ios.ts files are excluded in tsconfig.json.

cannot find module

This is from https://github.com/NativeScript/web-mobile-project project. I added line 5 to show the error. Also there is an error in line 13. It says that experimentaldecorators should be enabled. It is enabled in both config files but I still get this error because tsconfig.tns.json and tsconfig.json files are ignored.

This only happens if file extension is tns.ts. All modules in files without tns.ts extension are found and Atom editor does not show an error.

How can I solve this problem?

This is my tsconfig.json file:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom",
            "es6",
            "es2015.iterable"
        ],
        "baseUrl": "./",
        "paths": {
            "~/*": [
                "src/*"
            ],
            "*": [
                "./node_modules/tns-core-modules/*",
                "./node_modules/*"
            ],
            "@shared/*": [
                "src/app/shared/*"
            ],
            "@models/*": [
                "src/app/shared/models/*"
            ],
            "@core/*": [
                "src/app/core/*"
            ],
            "@components/*": [
                "src/app/components/*"
            ]
        }
    },
    "exclude": [
        "**/*.tns.ts",
        "**/*.android.ts",
        "**/*.ios.ts",
        "**/*.spec.ts"
    ]
}

This is tsconfig.tns.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "es2015",
    "moduleResolution": "node",
    "baseUrl": "./",
    "experimentalDecorators": true,
    "paths": {
      "~/*": [
          "src/*"
      ],
      "*": [
          "./node_modules/tns-core-modules/*",
          "./node_modules/*"
      ],
      "@shared/*": [
          "src/app/shared/*"
      ],
      "@models/*": [
          "src/app/shared/models/*"
      ],
      "@core/*": [
          "src/app/core/*"
      ],
      "@components/*": [
          "src/app/components/*"
      ]
    }
  }
}
zarax
  • 871
  • 1
  • 10
  • 30
  • `tscongif.tns.json` is just a typo while writing here? please double check the names. Make sure your ns extension config reads `tns`. – Manoj Dec 24 '18 at 17:32
  • It is a typo. I didn't change the file name. Fixed it in the post. – zarax Dec 24 '18 at 17:53
  • @zarax Did you find a solution? I have the same problem here.. – manzapanza Jun 12 '19 at 20:16
  • @manzapanza No solution yet. I just ignore them. – zarax Jun 13 '19 at 09:26
  • I have the same problem and its driving me crazy. Using angular I get the "experimental decorators" warning everywhere even though I have "experimentalDecorators: true" in all my tsconfig.json files. All non "**.tns.ts" files are fine however. For your "platform" error I import from "tns-core-modules/platform" instead and I don't get a warning/error. – crowmagnumb Jul 31 '19 at 19:14
  • @crowmagnumb in vsCode enable this: JavaScript › Implicit Project Config: Experimental Decorators, it fixed the problem for me. I don't know how to resolve in intellij though. – funder7 Jul 17 '20 at 12:30
  • @Funder Thanks, but this error was about the Atom editor. Although I might be slowly switching to VSCode. One thing that was stopping me was the fact that VSCode also had this issue. But being not very versed in it can you explain how I enable the setting you mention? – crowmagnumb Jul 17 '20 at 16:19

0 Answers0