The plugin called typescript from Rollup is throwing an error message with code TS2307. It says it cannot locate the module named 'App.svelte' or its related type declarations

I'm encountering a specific issue with my svelte project

main.ts

import App from './App.svelte';

const app = new App({
  target: document.body,
});

export default app;

The first line is triggering a warning message

Plugin typescript: @rollup/plugin-typescript TS2307: Cannot find module './App.svelte' or its corresponding type declarations.

Despite having what seems to be the correct configuration and adding

"@tsconfig/svelte": "^2.0.1",
in my tsconfig file, I still encounter this issue

rollup.config.js

import svelte from 'rollup-plugin-svelte';
// Other rollup plugins listed here

// Configuration settings and plugins specified within the file

tsconfig.json

{
  // tsconfig settings listed here
}

While I am able to import .svelte files within other .svelte files, the problem arises when trying to import .svelte files into .ts files

Answer №1

@tsconfig/svelte version 1.x originally included

"types": ["svelte"]
. This ensured that TypeScript could recognize the ambient Svelte type definitions and understand that Svelte imports were valid. However, this also inadvertently blocked other ambient type definitions, causing confusion especially with Jest. To address this issue, version 2 of @tsconfig/svelte has removed the types field, requiring users to manually add the ambient definition or a reference to it.

To set up the ambient type definition, create a file named global.d.ts within your src folder:

/// <reference types="svelte" />

This serves the same purpose as the previous

"types": ["svelte"]
configuration in the tsconfig.json, informing TypeScript where to locate the ambient type definition.

If you encounter errors with @tsconfig/svelte version 2, it is recommended to check your TypeScript version. If using TypeScript 4.5, there may be a known bug that affects tripleslash types like these under certain circumstances. To resolve this, consider downgrading to TypeScript 4.4.x or updating Svelte to its latest version, which contains a fix to restore functionality.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Confounding Typescript Type Bindings

I am facing an issue with my Typescript component that uses react-jss and the classes object for styling. The error message I'm getting is: Binding element 'classes' implicitly has an 'any' type., and I'm struggling to find a ...

detecting modifications in the div tag

Utilizing a third-party library to scan QR codes is a necessity. Once the scanning is finished, the content within the <div id="qr-code-status"></div> element changes accordingly. While the QR code is being scanned, the innerText of t ...

Exploring the functionality of the Angular 7 date pipe in a more dynamic approach by incorporating it within a template literal using backticks, specifically

I have a value called changes.lastUpdatedTime.currentValue which is set to 1540460704884. I am looking to format this value using a pipe for date formatting. For example, I want to achieve something like this: {{lastUpdatedTime | date:'short'}} ...

What is the process to activate a function within a component once a service method has been run?

I'm currently working on a chart configuration using amCharts, where an eventListener is registered for the bullets. This event listener then triggers another function in my chart service. My goal is to activate a method in my component as soon as th ...

Property '{}' is not defined in type - Angular version 9.1.1

Currently, I am working with Angular CLI version 9.1.1 and I am attempting to update certain data without updating all of it. form: UserInfo = {adresse : {}}; UserInfo.interface export interface UserInfo { id_user: string; username: string; em ...

Error in Typescript: The type 'string' cannot be assigned to the type '"allName" | `allName.${number}.nestedArray`' within the react hook form

Currently, I am tackling the react hook form with typescript and facing a challenge with my data structure which involves arrays within an array. To address this, I decided to implement the useFieldArray functionality. allName: [ { name: "us ...

Prisma does not automatically update interfaces

I am currently working on a Nest.js project with Prisma as my ORM. However, I have encountered an issue that needs to be addressed: My User model is quite simple: model User { id String @id @default(uuid()) @db.Uuid firstName ...

Modifying the color of the error icon in Quasar's q-input component: a step-by-step guide

https://i.stack.imgur.com/4MN60.png Is it possible to modify the color of the '!' icon? ...

What causes a Typescript error when attempting to escape a newline character?

My approach is quite simple: I concatenate multiple strings and format them to make them more readable. info() { return "x: " + this.xpos.toString() + "\n" \ + "y: " + this.ypos.t ...

Ways to enable Urql (typescript) to accept Vue reactive variables for queries generated using graphql-codegen

I'm currently developing a Vue project that involves using urql and graphql-codegen. When utilizing useQuery() in urql, it allows for the use of Vue reactive variables to make the query reactive and update accordingly when the variables change. The ...

In Vue 3, the v-model feature is utilized as parameter passing instead of using :prop and @emit

I've been trying to implement two-way binding using v-model in Vue.js based on this article. The idea is to pass values from a parent component to a child component with automatic event emission when the value changes in the child component. However, ...

Tips for executing a function when nearing the bottom of a scroll:

I have incorporated the angular2-infinite-scroll plugin, specifically version 0.1.4. You can view my plunker here. Currently, the function onScrollDown() only runs once at the beginning when scrolling. I attempted to adjust the values for infiniteScroll ...

Error with declaring TypeScript class due to private variable

When defining a TypeScript class like this: export class myClass { constructor(public aVariable: number) {} private aPrivateVariable: number; } and trying to initialize it with the following code: let someVar: myClass[] = [{ aVariable: 3 }, { aV ...

Encountered an error of 'No overload matches this call' while configuring ContextApi alongside useReducer with Typescript

I am currently setting up ContextApi and useReducer with typescript. I am encountering an error with my "issuesInitialState" variable in useReducer, where I receive the following message: No overload matches this call. Overload 1 of 5, '(reducer: ({ ...

Encountering a GitHub REST API CORS issue while attempting to fetch a public repository's git archive

I'm currently working on developing an Angular application that will be hosted on my GitHub pages using a custom verified domain. Below is the code I am using to call the GitHub API in order to obtain the zip archive of one of my (public) repositori ...

Exploring the Angular 2 ngFor Directive's Impact on View Lifecycle Triggers

Is there a way to trigger an animation after updating an array of values that is bound to the template HTML using *ngFor? In order for my animation to be meaningful, it needs to be triggered after the view has been updated with the most current values. I ...

Windows drive letter casing error when using Yarn and NextJS

Today, I set up a fresh project using Yarn and NextJS on my Windows computer. When I try to start the project, I encounter an error stating that the casing is "invalid" for the project directory. The specific errors I am facing are: Invalid casing detecte ...

What steps can be taken to resolve the error message "Using 'null' as an index type is not allowed."?

In my TypeScript code, I have a variable called lang declared as a string type value, and a variable called direction declared as an object with two elements. I also have a function that is supposed to return the value of the direction object based on th ...

"Angular allows for the reappearance of an alert even after it has been dismissed

Currently, I am engaged in an Angular project where I am implementing a feature to add objects to a table. However, not all of the object's fields are considered valid, and I need to notify the user through alerts. I am facing an issue where, after di ...

Passing properties to a component from Material UI Tab

I have been attempting to combine react-router with Material-UI V1 Tabs, following guidance from this GitHub issue and this Stack Overflow post, but the solution provided is leading to errors for me. As far as I understand, this is how it should be implem ...