webpackvisual-studio-codeintellisensecompiler-optionsvscode-jsconfig

VScode: How to autocomple json/scss/image file paths from shortcut paths specified in jsconfig shortcuts


When doing imports, intellisense will suggest autocompletion names when I am trying to import a React .jsx component. Nothing will be suggested when I am trying to import json or scss files though.

I have a set of aliases that I set up in my webpack.config.js

  resolve: {
    extensions: ['.css', '.js', '.jsx'],
    alias: {
      'src': path.resolve(__dirname + '/src'),
      'data': path.resolve(__dirname + '/src/data'),
      'assets': path.resolve(__dirname + '/src/assets'),
      'images': path.resolve(__dirname + '/src/assets/images'),
      'styles': path.resolve(__dirname + '/src/assets/styles'),
      'components': path.resolve(__dirname + '/src/components'),
      'types': path.resolve(__dirname + '/src/types'),
      'functions': path.resolve(__dirname + '/src/functions'),
      'pages': path.resolve(__dirname + '/src/pages')
    }
  },

And because I want intellisense to autocomplete these paths, I created a jsconfig.json

    {
        "compilerOptions": {
          "jsx": "react",
          "allowSyntheticDefaultImports": true,
          "target": "es6",
          "baseUrl": "./",
          "paths": {
            "src": ["./src"],
            "src/*": ["./src/*"],
            "data": ["./src/data"],
            "data/*": ["./src/data/*"],
            "assets": ["./src/assets"],
            "assets/*": ["./src/assets/*"],
            "images": ["./src/assets/images"],
            "images/*": ["./src/assets/images/*"],
            "styles": ["./src/assets/styles"],
            "styles/*": ["./src/assets/styles/*"],
            "components": ["./src/components"],
            "components/*": ["./src/components/*"],
            "types": ["./src/types"],
            "types/*": ["./src/types/*"],
            "functions": ["./src/functions"],
            "functions/*": ["./src/functions/*"],
            "pages": ["./src/pages"],
            "pages/*": ["./src/pages/*"],
          }
        },
        "exclude": ["node_modules"],
        "checkJs": "true"
      }


I have path intellisense installed

I also have my keybindings.json set up to be

[
    { "key": ".", "command": "" }
]

I also added "typescript.suggest.paths": false to my .vscode/setting.json as suggested in the path intellisense documentation although I am not using typescript. This is just a javascript project.


Solution

  • I had to add

        "compilerOptions": {
            "resolveJsonModule": true,
    

    to my jsconfig.json for json