Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Go To Definition / open file in JavaScript import statements? #146502

Closed
alikim-com opened this issue Apr 1, 2022 · 3 comments
Closed
Assignees

Comments

@alikim-com
Copy link

alikim-com commented Apr 1, 2022

I have a html file with JavaScript module in it, like so:

<script type="module">

    import * as LOADER from './path/loader.js'

    import { add } from '/path/ui.js'

  </script>

I run a server at localhost, so I have a local folder set as a root (under Win10) and the file works perfectly in the browser.

When I open this file in VS Code, it doesn't understand paths mentioned in import statements, relative or absolute, I can't use Go To Definition or Peek or open imported .js files.

Is it possible to make VS Code work with import statements?

I created jsconfig.json file in the same folder as the html file:

{
  "compilerOptions": {
    "module": "commonjs",
    "baseUrl": ".",
    "paths": {
      "/*": ["./*"]
    }
  },
  "include": ["/path/*"]
}

but it doesn't make any difference.

vscode

@jpbnetley
Copy link

I hade the same problem, but got it working by changing the jsconfig.json to just reference the baseUrl.

{
  "compilerOptions": {
    "baseUrl": "src"
  }
}

I guess if you want to do the same, it might look like this

{
  "compilerOptions": {
    "baseUrl": "."
  }
}

Hope this helps.

@alikim-com
Copy link
Author

I hade the same problem, but got it working by changing the jsconfig.json to just reference the baseUrl.
...
Hope this helps.

As you can see from the file I currently have, I already put baseUrl in it and it doesn't help.

@mjbvz mjbvz assigned aeschli and unassigned mjbvz Apr 1, 2022
@aeschli
Copy link
Contributor

aeschli commented Apr 4, 2022

We currently don't follow import statements in embedded JavaScript.
Covered by #114115

@aeschli aeschli closed this as completed Apr 4, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants