The trick to getting VSCode to resolve the "@" symbol in imports

In a Vue.js project that utilizes Webpack, the imports use @ as an alias for the src directory. How can I configure VSCode to properly resolve this alias and enable intellisense for those imports?

I have come across various methods online on setting up aliases in VSCode, such as using jsconfig.json or tsconfig.json. Despite configuring both files, none of them seem to be effective.

This is how my jsconfig.json looks like:

{
  "compilerOptions": {
    "target": "es6",
    "allowSyntheticDefaultImports": false,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "exclude": ["node_modules", "dist"]
}

I was hoping that by configuring VSCode in this way, it would successfully resolve the alias in the path and enable functions like intellisense and peeking definition.

Answer №1

Within the scope of my current project, I've implemented a jsconfig.json file at the root directory with the following settings :

{
  "compilerOptions": {
    "target": "es2017",
    "allowSyntheticDefaultImports": false,
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/*"],
    }
  },
  "exclude": ["node_modules", "dist", "docs"]
}

It's proved to be effective for my project.

I'm not entirely sure about the functionality of moduleResolution in your configuration, and the baseUrl I've specified points to the root folder in my instance.

You can refer to the VS Code documentation for more information: https://code.visualstudio.com/docs/languages/jsconfig#_using-webpack-aliases

Give it a try and let me know if it improves your setup?

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

Encountering the error message "require is not defined" in the browser while utilizing gulp-browserify for my React.js modules

I am currently working on using gulp-browserify for creating a bundle.js file that will be utilized in the client's browser to initiate rendering of React components. Below is my App.js file: /** @jsx React.DOM */ var React = require('react&apo ...

When the window size is minimized, containers are colliding with each other

On smaller window sizes or certain small screen phones, the buttons are overlapping the heading. Take a look at the code below: <style> body { font-family: Arial, Helvetica, sans-serif; } .x2 { position: absolute; left: 50%; top: 50%; tran ...

Issue with Sequelize failing to update a row within a database table

This is my first experience using sequelize. Within my database, I have a table named feed containing columns such as ID, caption, and url. In my controller, there is a straightforward function aimed at updating a row within this table: router.patch(' ...

Updating Sailsjs Localization Settings

After working with Sails.js for a while, I am interested in finding out if it is possible to manually adjust the localization from the controllers based on the URL. For example, accessing http://example.com/en would display the English version, while http ...

Identifying when an image element is within the viewport using jQuery Mobile

Looking for a solution to bypass the image size download limit on mobile devices by detecting when an image is in view and then downloading it. Also interested in replacing the image src with a smaller image to free up memory. Any tips on how to efficientl ...

Updating the state of a disabled field in a React component

I have been trying to display a default value and disable the field. The values are successfully displayed but the state is not getting updated. Can someone please guide me on how to update the state of a disabled field? I have put in a lot of effort but h ...

The marker on the Three JS globe is constantly visible inside the globe or positioned far outside its boundaries

As a beginner in programming and React three fiber, I am struggling to understand why the marker I place on the globe using geolocation data won't stay attached. Despite my attempts to convert latitude and longitude to Cartesian coordinates, the marke ...

The autocomplete feature in Visual Studio Code seems to be malfunctioning

I recently began learning node.js and decided to use Visual Studio Code as my text editor. However, I encountered an issue where I am unable to type "require('something')". Every time I start typing "require" followed by a "(", it automatically c ...

Update the Material-UI theme to a personalized design

I am currently using Material-UI in my React project. However, I'm facing some difficulties in applying a theme globally. Up until now, I have only managed to apply the theme to individual components like this: import { MuiThemeProvider, createMuiTh ...

Translation of country codes into the complete names of countries

Currently, my code is utilizing the ipinfo.io library to retrieve the user's country information successfully. This is the snippet of code I am using to fetch the data: $.get("https://ipinfo.io?token=0000000000", function(response) { console.log ...

Discovering the Secrets of Laravel 5: Harnessing the Power of Vue.js to Access Data Attribute Values

I'm a beginner in vue js. Within our app, we have implemented validation to check if a value already exists in the database. I would like to enhance this feature by making it dynamic. To achieve this, I have added a data attribute to my field which is ...

Discovering the means by which current route meta fields can be accessed in a typical JavaScript module for VueJs

I'm currently working on an application with the following route setup: const router = new Router({ mode: 'history', scrollBehavior: () => ({ y: 0 }), routes: [ { path: '/', component: HomePage, meta: { pageType: &apos ...

javascript is failing to display the appropriate message at the correct moment

Wrote a code to handle the type of message I should get, looping over all the rows in the table to find matching conditions. These are my conditions: - If all rows have data-mode="success" and data-pure="yes", it's correct and successful. - If any row ...

Retrieving information from a nested element in React

Although it may seem straightforward, I'm having trouble finding the necessary information... Firstly, here is the parent component code: import { useState } from "react" import Input from "./form/Input"; import { useNavigate, use ...

Issue: The automation server is unable to generate the object

I am encountering an issue with the code snippet below, which is causing an error specifically in the IE-11 web browser: var excApp = new ActiveXObject("Excel.Application"); The error message being displayed is: Error: Automation server can't create ...

Encountering a 500 server error while trying to send an email using SendGrid in conjunction

Seeking help on integrating an email capture form into a NextJS site by following this tutorial: Simplified the form to only include the email field. The content of my api/contact.js file is as follows: const mail = require('@sendgrid/mail'); ...

Navigating in Angular JS using $location function

I'm facing an issue with navigating between web pages using Angular JS. The first web page is index.html, followed by main.html. Additionally, there is a myscript.js file and style.css, although the latter is not relevant to this problem. My goal is t ...

What methods can I use to teach emacs to distinguish between my PHP, HTML, and JavaScript code as I write?

While working with emacs and writing PHP, I often find myself needing to include HTML code and would appreciate a way to differentiate the syntax highlighting between PHP and HTML. Similarly, when adding JavaScript to an HTML file, I would like to know h ...

Tips for obtaining consistent legend and tooltip for dynamically generated data in Vue using vue-chartjs

I am currently working on creating a vue chart using vuechartjs that would display the numbers 10, 20, 30, 40, 50 repeatedly over several years. My main issue is getting the legend and tooltip to function correctly. At the moment, the label just shows an ...

Troubleshooting JavaScript for Sidebar Disappearance due to marginRight and display CSS Issue

I need to adjust the layout of my website so that the sidebar disappears when the window is resized below a certain width, and then reappears when the window is expanded. Here is the HTML code: <style type="text/css"> #sidebar{ width:290 ...