Skip to content

An import path cannot end with a ".ts" extension. (TS 2.0.3) #162

Closed

Description

@jlost

Generating a new project with jspm init and specifying typescript as my transpiler, the convention for picking up typescript files is as follows:

packages: {
    "pets-gui": {
      "main": "main.js",
      "meta": {
        "*.ts": {
          "loader": "plugin-typescript"
        }
      }
    }
  }

My understanding is that this means everything with the .ts extension in the import is run through the typescript transpiler plugin.

However, Typescript 2.0.3 (called externally for intellisense) will report this as an error: An import path cannot end with a ".ts" extension. Consider importing './app.routing' instead, for instance. Of course, if I do that, the .ts files aren't transpiled by systemjs, and it just reports 404's as it tries to load "./app.routing" which doesn't exist.

Is there a work-around so I don't have to choose between SystemJS and my intellisense?

Apologies if this is the wrong place to raise this issue. Originally reported at jspm/jspm#2103

0.17.0-beta.28
Running against local jspm install.
devConfig: {
    "map": {
      "plugin-typescript": "github:frankwallis/plugin-typescript@5.1.2"
    },
    "packages": {
      "github:frankwallis/plugin-typescript@5.1.2": {
        "map": {
          "typescript": "npm:typescript@2.0.2"
        }
      }
    }
  },

Activity

  1. frankwallis commented on Oct 2, 2016

    @frankwallis
    Owner

    I think you need to add the defaultExtension: "ts" setting, see here for example

  2. aluanhaddad commented on Oct 2, 2016

    @aluanhaddad
    Contributor

    @jlost using jspm 0.17.0-beta.28 here and defaultExtension: "ts" on my package config works perfectly.

    Here is what your config should look like.

    packages: {
        "pets-gui": {
          "main": "main.ts", // or just "main"
          "defaultExtension" : "ts",
          "meta": {
            "*.ts": {
              "loader": "plugin-typescript"
            }
          }
        }
      }

    Note that in the above you cannot use "main.js" it must be "main.ts" or simply "main".

    The change in TypeScript behavior should not affect you. Importing files with an explicit .ts extension was never supposed to work and it doesn't need to. Even though it worked in the past it was a bad practice because it coupled your source to how it was transpiled.

  3. mavericken commented on Oct 27, 2016

    @mavericken
    Contributor

    @aluanhaddad

    The change in TypeScript behavior should not affect you. Importing files with an explicit .ts extension was never supposed to work and it doesn't need to. Even though it worked in the past it was a bad practice because it coupled your source to how it was transpiled.

    Users of plugin-typescript are very much affected. Now we must have separate directories for TS, JS, TSX, and JSX files. So we get no benefits from the decoupling. If we ever needed to change the file extension, we will still have to change our import statements and the file name, but now we also have to change the directory.

    Edit: @aluanhaddad enlightened me as to why extensions can't work. I still feel we need a way to handle multiple transpilation types in a single directory.

    microsoft/TypeScript#11901

  4. aluanhaddad commented on Oct 29, 2016

    @aluanhaddad
    Contributor

    @mavericken I see the problem. You have multiple source extensions in the same directory and thus setting "defaultExtension": "ts" does not resolve the problem. Actually, in TypeScript 2.0, TypeScript will try to resolve a file with a .js extension to a .ts or .tsx file if not found. So perhaps using .js extensions for your imports would be more effective.

  5. mavericken commented on Oct 31, 2016

    @mavericken
    Contributor

    @aluanhaddad Well, for TypeScript compiler itself, extension-less can already do the same thing, as it will also find the .ts or .tsx file. I feel that the role of plugin-typescript is to allow any valid typescript to be imported into SystemJS. Right now, this is not the case, as a valid typescript can contain both TS and TSX files in the same folder, but SystemJS + Plugin-Typescript cannot do that, so currently there exists valid typescript programs which Plugin-Typescript cannot support.

    Edit: I have proposed a change to plugin-typescript that could handle it: #173
    Edit again: I made a separate module to handle my concerns
    https://www.npmjs.com/package/one-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions