javascript - How Can I Fix VSCode Import Path Suggestions In Lerna Monorepo? - Stack Overflow

VSCode does a great job with autosuggesting imports, however inside a (Lerna) monorepo it only suggests

VSCode does a great job with autosuggesting imports, however inside a (Lerna) monorepo it only suggests relative paths from one package to another, for example:

import example from '../../../@scope/example/lib/index.html'

I need to refer to other packages using their package names:

import example from '@scope/example';

My jsconfig.json which is at the root of my monorepo:

{
  "pilerOptions": {
    "target": "es6",
    "jsx": "react"
  },
  "include": ["**/src/**/*.js"],
  "exclude": [
    "**/node_modules/*",
    "**/dist/*",
    "**/coverage/*",
    "**/demo/*",
    "**/lib/*",
    "**/public/*"
  ]
}

Is there any way to get the correct autopletion in VSCode?

Note: There is a plugin available, but it only works with .ts files.

VSCode does a great job with autosuggesting imports, however inside a (Lerna) monorepo it only suggests relative paths from one package to another, for example:

import example from '../../../@scope/example/lib/index.html'

I need to refer to other packages using their package names:

import example from '@scope/example';

My jsconfig.json which is at the root of my monorepo:

{
  "pilerOptions": {
    "target": "es6",
    "jsx": "react"
  },
  "include": ["**/src/**/*.js"],
  "exclude": [
    "**/node_modules/*",
    "**/dist/*",
    "**/coverage/*",
    "**/demo/*",
    "**/lib/*",
    "**/public/*"
  ]
}

Is there any way to get the correct autopletion in VSCode?

Note: There is a plugin available, but it only works with .ts files.

Share Improve this question edited Dec 11, 2018 at 10:18 Undistraction asked Dec 10, 2018 at 18:19 UndistractionUndistraction 43.4k63 gold badges206 silver badges336 bronze badges 2
  • Have you tried configuring anything so far, such as creating a tsconfig or jsconfig for example? – Matt Bierner Commented Dec 10, 2018 at 19:18
  • @MattBierner I've added my jsconfig.json file to the question. – Undistraction Commented Dec 11, 2018 at 10:20
Add a ment  | 

1 Answer 1

Reset to default 5

You can configure paths in a jsconfig.json to let VS Code's tooling know how to resolve @/ paths.

In your jsconfig.json, add:

{
  "pilerOptions": {
    "baseUrl": ".",
    "paths": {
       "@scope/example/*": [ "./path/to/scope/example/*" ]
    }
  },
   "exclude": [
     "node_modules"
  ]
}

You can configure paths to map from any path prefix to a subdirectory in your workspace. See the path mapping documentation for more details

Note that paths only effects imports of javascript or typescript files; an .html import still won't work properly

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745354298a4624023.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信