When utilizing TypeScript with Nuxt3, the error message "Module '#imports' or its corresponding type declarations could not be found" may be encountered

I have extensively searched for a solution to this issue, but unfortunately, I have not been able to find any results.

When working with a very basic component, I encounter the following error: Cannot find module '#imports' or its corresponding type declarations

import { setPageLayout } from '#imports';

The code functions correctly, but it seems to be related to types and not recognizing the imports with "#" symbol.

I have followed all the configurations outlined in the documentation. Does anyone have any suggestions?

Here is my tsconfig:

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "ESNext",
    "moduleResolution": "Node",
    "lib": [
      "ESNext",
      "ESNext.AsyncIterable",
      "DOM"
    ],
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ],
      "@/*": [
        "./*"
      ]
    },
    "types": [
      "@nuxt/types",
      "@nuxt/typescript-build",
      "@types/node"
    ],
    "resolveJsonModule": true,
    "noImplicitAny": false,
  },
  "exclude": [
    "node_modules"
  ],
  "extends": "./.nuxt/tsconfig.json"
}

nuxt.config file:

import type { NuxtConfig } from '@nuxt/types';

const config: NuxtConfig = {
  buildModules: ['@nuxt/typescript-build'],
  vue: {
    config: {
      productionTip: false,
      devtools: true
    }
  }
};

export default config;

vue-shim.d.ts file:

declare module "*.vue" {
  import Vue from 'vue'
  export default Vue
}

Answer №1

Just had a breakthrough!

It seems like Nuxt is having trouble recognizing the "#imports" alias. The solution is to make an adjustment in your tsconfig.json file:

{
  "compilerOptions": {
    "paths": {
      "#imports": [".nuxt/imports.d.ts"]
    }
  }
}

Implementing this change resolved the issue right away.

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

What is the best way to trigger a re-render of a Vue component after a change in Vuex

I'm interested in developing a custom component to modify the basemap of a leaflet map without relying on L.control.layers. To achieve this, I created a sidebar component that offers options to switch between different basemaps. In my implementation, ...

Guide to modifying the root directory when deploying a Typescript cloud function from a monorepo using cloud build

Within my monorepo, I have a folder containing Typescript cloud functions that I want to deploy using GCP cloud build. Unfortunately, it appears that cloud build is unable to locate the package.json file within this specific folder. It seems to be expectin ...

What is the method for incorporating input value into a li list item?

I am attempting to insert the content of an input as a list item (<li>) in an unordered list (<ul>). I managed to add it by connecting the value to the array list of list items. However, it disappears when I clear the input field. How can I re ...

In a Vue application, how can the API path be determined during the build by utilizing environment variables?

I am looking for a way to dynamically change the 'root path' of my site's API in a Vue application. I want the API path to be determined during the build process based on a variable value. This feature is available in Angular, but I'm n ...

The peculiar type intersection of 'string & {}'

There is a TypeScript syntax often seen in some libraries like this: type AriaRole = 'alert' | 'tree' | 'treegrid' | 'treeitem' | (string & {}); Can someone explain the meaning of string & {}? It represent ...

TypeScript's function types

Regarding my previous inquiry: Transforming PropTypes compatibility into TypeScript If I have this specific function to pass: const displayIcon = () => <span class='material-icons'>account_circle</span> And, the displayIcon func ...

Having trouble receiving notifications from the Telegram API

I have integrated mtproto-core library (https://github.com/alik0211/mtproto-core) into my Vue application to communicate with the Telegram API. Most of the functionalities are working smoothly, but I'm encountering an issue when trying to fetch updat ...

Create vertical boundaries with the chartjs-plugin-annotation in conjunction with vue-chartjs

Trying to set 2 vertical lines as thresholds for a list of results from various tests. The issue arises when attempting to place the lines at values that do not exist within the result set, causing them to disappear. However, with the code below, the lines ...

"Learn how to dynamically update a value based on the selected option in a drop-down menu in Angular

Hello everyone. I am working on an angular project that includes a product page. Some products on this page can have multiple types, like so: Product ID-1 Type ID-1 Price-$10 Product ID-1 Type ID-2 Price-$15 Product ID-1 Type ID-3 Price-$25 In this sce ...

Sending array data from parent to child component in Angular

I am currently utilizing the ng2-chart library and I'm trying to pass data from a parent component to a child component. The data is retrieved from an API source. However, I am facing an issue where the information is not being loaded: export class P ...

Executing "mounted" in VueJS SSR with Quasar: A step-by-step guide

In accordance with the documentation: Given that there are no dynamic updates, only beforeCreate and created Vue lifecycle hooks will be triggered during SSR. This implies that any code within other lifecycle hooks like beforeMount or mounted will sole ...

Creating a dropdown menu that interacts with a specific element: step-by-step guide

TL;TR How can I achieve the following: getMyComponent(selectedMyComponentID).complexOperation() This seems like a simple and practical task, such as selecting an item from a dropdown menu. More Information Imagine that I am creating some sort of editor ...

Ways to utilize multiple tsconfig files within VS Code

My project structure in Visual Studio Code is fairly common with a client, server, and shared directory setup: ├── client/ │ ├── tsconfig.json ├── shared/ ├── server/ │ ├── tsconfig.json ├── project.json The tw ...

Is it possible to achieve real-time two-way data binding in a reactive form by passing values from one formgroup to another formgroup? If so, how

There are 2 FormGroups named orderForm and parcelForm on a page. The parcelForm is generated dynamically within a FormArray. In the parcelForm, there are FormControls like net_weight and gross_weight, while the OrderForm has FormControls such as total_net_ ...

The Vue.js component is only refreshing after I manually refresh the browser page

As a newcomer to Vue.js and other reactive frameworks, I am still learning the ropes. I have a component that needs to update whenever there is a change. The goal is to display a balance from a specific login. <li :key="balance">Balance {{ balance ...

Tips for successfully interacting with dynamic text areas using Protractor:

My current project involves e2e testing for an Angular 4 application with Protractor. Despite my efforts, I am struggling to locate a unique id, class, name or text identifier for a specific textarea within the application code. I need assistance in find ...

Is the ng-selector in Angular2 not sorting items alphabetically as expected?

This code snippet demonstrates the use of ng-selector in an .html file <ng-selector name="company" [(ngModel)]="company_selected" [formControl]="loanApplyForm.controls['company']" ...

Issue encountered with JavaScript function within TypeScript file connected to HTML code

I am currently working on a simple SharePoint web part and encountering an issue with using a function from another module file in my main file. Snippet from the JSFunctions.module.js file (where I define my function): function getApi(){ [my code]... }; ...

Is there a way to restrict the type of a discriminated union in Typescript without having to list out all the individual cases explicitly?

As I work extensively with discriminated unions, a common issue arises: When dealing with a function parameter that is a discriminated union type, I often need to perform specific actions based on subsets of the union. Typically, I use the discriminant t ...

Error: Type 'string' is not valid for index signature in TypeScript

I encountered this issue with a function I have: const fieldsOrder = [ 'boo', ]; fieldsOrder.reduce((sortedRequest, key) => { if (key in request) sortedRequest[key] = request[key]; // Causing warnings here return sortedRequest; } B ...