Error TS2307: Module '@...' not located during JavaScript compilation

In my current Vue project, I am utilizing VueJs 3 with TypeScript and plan to package the application as a Desktop app using Electron.

When running vite, everything functions correctly. However, when I run npm run ts to convert TypeScript files to JavaScript, I encounter the following error:

src/main.ts:2:17 - error TS2307: Cannot find module './App.vue' or its corresponding type declarations.

2 import App from './App.vue'
                  ~~~~~~~~~~~

... (remaining errors omitted for brevity)

Found 10 errors in 2 files.

Errors  Files
     1  src/main.ts:2
     9  src/router/routes.ts:1

The issue arises due to the use of aliases in my configuration. Identifying the root cause has proven challenging as the compiler also encounters issues with the './App.vue' import in main.ts. What could be causing this configuration error?

Source code

vite.config.ts

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue()
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
      '@components': resolve(__dirname, './src/components'),
      '@stores': resolve(__dirname, './src/data/stores'),
      '@pages': resolve(__dirname, './src/pages'),
      '@scripts': resolve(__dirname, './src/scripts'),
      '@models': resolve(__dirname, './src/data/models'),
      '@enums': resolve(__dirname, './src/data/enums'),
    }
  },
  build: {
    outDir: 'build/vite',
    emptyOutDir: true
  },
  base: './'
})

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    
... (remaining json content omitted for brevity)
  
  "include": ["src/*"],
  "references": [{
    "path": "./tsconfig.node.json"
  }]
}

package.json

{
  "name": "mealpro",
  "displayName": "Mealpro",
  
... (remaining json content omitted for brevity)

  "devDependencies": {
    "@electron-forge/cli": "^7.4.0",
    
... (remaining dependencies omitted for brevity)
  }
}

Answer №1

After much trial and error, I finally found the solution to my problem. It turns out that the include path specified in the tsconfig.json file needed to be adjusted:

The Issue:

{
  ...
  "include": ["src/*"],
  ...
}

The Resolution:

{
  ...
  "include": ["src/electron/*"],
  ...
}

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

Sort the list alphabetically in Vue.js by clicking a button

I've been experimenting with Vue.js and having some trouble figuring out how to dynamically sort a list when clicking a button. Although I managed to successfully sort the list using the orderedBeers method, I can only see the changes in the inspecto ...

When the NPM package is imported as a whole, it shows up as undefined. However, when it

I've come across a peculiar issue in my code where importing the textile/hub package in Node.js and then destructuring it later results in an error. However, if I destructure it while importing, the program runs without any issues. Can anyone shed som ...

Having trouble choosing options within Material UI's Autocomplete Component?

I'm having trouble selecting the options displayed in MUI's autocomplete component. It seems that using renderOption is causing this issue. I want to show an image along with the title in the component options, but without using renderOption, I h ...

Having difficulty automatically populating a textarea with the chosen option from a datalist

Is there a way to automatically populate the Address field of a client in a textarea based on the input of the client's name in an input field? I have created a 'for loop' to retrieve a datalist of client names. For the address, I retrieved ...

Is there a way to retrieve information from a prior session without relying on cookies?

One of my projects involves entering a name and selecting checkboxes on a page, with the data being saved to a text file on the server using PHP. To retrieve the data for a specific name, I use the following PHP code: <?php $search = $_GET["name"]; $c ...

What causes CSS animations to suddenly halt?

Recently, I've been delving into the world of CSS animations and experimenting with some examples. Below is a snippet of code where two event handlers are set up for elements, both manipulating the animation property of the same element. Initially, th ...

Issues with the functionality of Angular Factory

Issues are arising with the controller not retrieving data correctly from the factory to display in the view. When all the data was stored in the controller, it worked fine. However, upon transferring it to the factory, the data no longer showed on the vie ...

Execute a function when an RXJS Observable has completed its operation

Using the RXJS Observable has been smooth sailing so far, but I now find myself needing to not only react to observer.next() but also when observer.complete() is called. How can I capture the OnComplete event of an RXJS Observable? The documentation for ...

The name 'console' could not be located

I am currently working with Angular2-Meteor and TypeScript within the Meteor framework version 1.3.2.4. When I utilize console.log('test'); on the server side, it functions as expected. However, I encountered a warning in my terminal: Cannot ...

Coloring in Charts.js based on values

Exploring the options for Charts.js to dynamically change fill color based on positive or negative point values has intrigued me. I am in the process of creating an accounting system for a friend's new company, and I need a chart that visually repres ...

A Guide to Retrieving Parameters and Request Body using Express and Typescript

When I use the PUT method, I encounter this issue: const createFaceList = (req: Request<{faceListId : string}>, res: Response, next: NextFunction) => { console.log(req.body.name); console.log("faceListID = " + req.params.faceListId); a ...

Keep the footer at the bottom of the screen without needing to define a 100vh in Material UI

In the process of developing my react app with MUI framework, I encountered various challenges in creating a sticky footer at the bottom of my screen. After exploring different solutions, one approach that I found most satisfactory is as follows: export de ...

What is the best way to retrieve a value from one array based on its index in React Native?

Looking to populate the centreValues array with values from another array const centreValues=[ { title:'Type', value:centreDetail.location_type }, { title:'Address', value:centreDetail.address1+centreDetail.ad ...

Looking to display a JSON-based menu using AngularJS?

Having trouble displaying a dropdown menu when trying to print a menu from a JSON file. https://i.sstatic.net/fNLxw.png JSON Data [{ "Option": "Request", "Name": "<a href=\"#/request\"><i class=\"material-icons left\ ...

best way to retrieve nested objects in react components

I am struggling to retrieve the price value in my react component. I have successfully used map to access object properties like images and id, but encountering issues when trying to access the price value. The error message I'm receiving is as follow ...

Instructions on changing the color and font weight of an asterisk within a Textfield using Material UI

Is there a way to style the asterisk in red and bold within a Textfield using material UI? I have a placeholder text without a label, as my label is null or empty. I would like to make the placeholder star RED. Is this possible? Here is the code snippet: h ...

Using ES6 without the need for jQuery, populate a select element with JSON data using Javascript

I have a json-formatted dataset that I want to incorporate into my select options. Here is the data: { "timezones": { "country": "Africa", "tz": "Africa/Abidjan" }, { "country": "America", "tz": "America/ ...

Node - Pause cycle to process incoming request$response

Despite trying numerous methods, I am struggling to find a solution. Since English is not my first language and I am relying on Google Translate, I may need to repeat myself multiple times for clarity. 1. Initially, I attempted using a For loop to wait u ...

Adjusting the maxContentLength and maxBodyLength values in Axios

While utilizing the "Axios" library to invoke a WCF method with file information and content as parameters, I encountered an issue. The file is read and transmitted as a base64 encoded string. However, when the file size surpasses a specific limit, Axios t ...

Wrapper component utilizing Vue.js with the beforeDestroy hook

For a wrapper component I'm working on, I need to ensure that Vuex is cleared when the component is closed. This component is registered in a menu, and the parent component is the default main page displayed when the page loads. The goal is to retrie ...