require.main.require imports do not work
See original GitHub issueTypeScript Version: 2.6.0-dev.201xxxxx
From: https://github.com/Microsoft/vscode/issues/35489#issuecomment-335689358
Code
const myModule = require.main.require('./file.js')
Run go to definition on myModule
Expected behavior:
Goes to defintion of myModule
Actual behavior:
Nothing happens. Looks like we don’t understand require.main.require
style imports
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Node.js, require.main === module - Stack Overflow
js so that code basically says that if require. main is the current module, then the current module is what was loaded from...
Read more >JavaScript require vs import - Flexiple
One of the major differences between require() and import() is that require() can be called from anywhere inside the program whereas import() ...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module ... up into separate modules that can be imported when...
Read more >Difference between node.js require and ES6 import and export
You can directly run the code with require statement. To run a program containing import statement you have to use experimental module feature ......
Read more >Using import and require in the same file - Node JS - YouTube
Found solution here: https://www.kindacode.com/article/node-js-how-to-use- import -and- require -in-the-same-file/
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I realise this may be a big feature for you, but consider that it is a widely-used alternative to requiring crazy paths like
../../../../../../foo/bar/baz.js
. So many people are using this approach now.I hope you can find a way to get this to work.
I am looking forward to this feature too. Intellisense is not able to understand
require.main.require
as alias forrequire
. But this method helps a lot for readability of code when you have files in deeper folder structures.