question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

require.main.require imports do not work

See original GitHub issue

TypeScript 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:open
  • Created 6 years ago
  • Reactions:8
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
grokky1commented, Oct 12, 2017

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.

4reactions
rafaelmaeuercommented, Jul 24, 2018

I am looking forward to this feature too. Intellisense is not able to understand require.main.require as alias for require. But this method helps a lot for readability of code when you have files in deeper folder structures.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found