Skip to content

Error: Could not resolve TypeScript file without .ts extension #159

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

Closed
hbbio opened this issue May 29, 2020 · 6 comments
Closed

Error: Could not resolve TypeScript file without .ts extension #159

hbbio opened this issue May 29, 2020 · 6 comments
Labels
next-major will be fixed in the next major

Comments

@hbbio
Copy link

hbbio commented May 29, 2020

Describe the bug

When using Svelte with an external script, in TypeScript, which itself imports components from other .ts files, we can't omit the .ts extension for import.

Otherwise, build fails with:

src/main.ts → public/build/bundle.js...
[!] Error: Could not resolve './initials' from src/App.svelte

Note that adding the .ts extension solves the problem with svelte-preprocess but then raises the following TypeScript error:

src/main.ts → public/build/bundle.js...
src/App.svelte:1:26 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './initials' instead.

To Reproduce

Cf. hbbio/svelte-ts@4ae0dd0

Expected behavior
Ability to import TypeScript files without the ts extension.
Information about your project:

  • svelte 3.23.0
  • typescript 3.9.3
  • svelte-preprocess 3.7.4
  • rollup
@hbbio
Copy link
Author

hbbio commented May 29, 2020

The temporary fix to add the .ts extension (despite ts error) does not work if the imported file is in a different directory: It tries to resolve the file using the path of the .svelte component.

@kaisermann
Copy link
Member

kaisermann commented Jul 7, 2020

Fixed in v4 as we're now only transpiling ts to js. Import resolution should be configured from the bundle side 😁 .

@MALIK-0
Copy link

MALIK-0 commented Aug 20, 2020

@kaisermann I'm using svelte-preprocess (4.1.1) and svelte (3.17.3) and face the same issue.

routes/index.svelte

// does not work
import { db } from "../firebase/firebase";

// does work, but file extension should not be used
import { db } from "../firebase/firebase.ts";

package.json

"sapper": "^0.28.0",
"svelte": "^3.17.3",
"svelte-preprocess": "^4.1.1",

@MALIK-0
Copy link

MALIK-0 commented Sep 12, 2020

@kaisermann I'm still facing this issue and it's stopping me from using Typescript. If I add the .ts extension in the import everything compiles fine but I get no intellisense. If I remove the .ts extension I get intellisense but compiling stops working.

Can you point me in the right direction?

@kaisermann
Copy link
Member

@TobiasMalikowski Is your bundler configured to automatically resolve ts extensions?

@MALIK-0
Copy link

MALIK-0 commented Sep 12, 2020

@kaisermann Thanks for the quick reply. Yes it is, and in addition I could resolve it just in time :). The issue was caused by rollup-plugin-typescript2. I downgraded to version 0.21.0 and now the issue is resolved.

Just in case some else has this issue, this GitHub Issue pointed me in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next-major will be fixed in the next major
Projects
None yet
Development

No branches or pull requests

3 participants