Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output: Import statement must be with .js not .ts #1208

Closed
VienDinhCom opened this issue Nov 7, 2020 · 3 comments
Closed

Output: Import statement must be with .js not .ts #1208

VienDinhCom opened this issue Nov 7, 2020 · 3 comments
Labels

Comments

@VienDinhCom
Copy link

VienDinhCom commented Nov 7, 2020

Describe the bug

Input code

// sum.ts
export function sum(a: number, b: number) {
  return a + b;
}
// main.ts
import { sum } from './sum.ts';

console.log(sum(1, 2));

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    }
  }
}

Result

// main.js
import { sum } from './sum.ts';

console.log(sum(1, 2));

Expected result

// main.js
import { sum } from './sum.js';

console.log(sum(1, 2));

The import statement must be with .js. Not .ts

Version
The version of @swc/core: 1.2.37

@kwonoj
Copy link
Member

kwonoj commented Dec 20, 2021

I believe this is related with #3043 also it's correct behavior as-is currently.

Linked issue's comment explains it

See @RyanCavanaugh's comment here: microsoft/TypeScript#41887 (comment)

TypeScript doesn't modify JavaScript code you write, the import path you write should be the one you want to appear in the output .js file

Actually, if you try latest tsc (https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEZwGZQiOAcgDoB6VfAU2JlUIG4g) you'll get error instead:

An import path cannot end with a '.ts' extension. Consider importing './some.js' instead.

If swc's bundler or other tool's resolver cannot resolve module with full extension (I believe for some cases it's failing) that's something to fix, but I believe swc should not try to modify import specifier by its own.

/cc @kdy1 , in my opinion I'd like to suggest to close this - and if we need, we can implement error out as same as tsc does.

@kdy1
Copy link
Member

kdy1 commented Dec 20, 2021

Yeah, I think you are right.
Thanks!

@kdy1 kdy1 closed this as completed Dec 20, 2021
@kdy1 kdy1 added invalid and removed C-bug labels Dec 20, 2021
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants