You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the analysis of module imports in .js files is limited to the known require call. require.main is not a pattern the compiler looks for. it is also early in the compilation process to know that require.main.require is an alias to require.
Mohamed Hegazy (@mhegazy) Worse yet, require.main.require isn't strictly an alias to require - it's a require relative to the package entrypoint... Something we don't currently define.
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.
Reacted by José Gonçalves, Théo Mouchabac and Andy Chan
I am not sure if this is the same issue, but what I want is to have the types in the current package, but I want the root package to include 'mongodb'.
When I do the following:
importmongo= require.main.require('mongodb')
I get the following error:
Cannot find namespace 'require'.
However, the following works, but isn't what I want:
Apparently require.main.require is referencing the Main package of your program, i. e., the entry script. When running with vscode code & debug tool, this package appears to be something else rather than my node js main process, because it fails to find the module require inside the main.
Activity
[-]require.main.require does not have path intellisense [/-][+]require.main.require imports do not work[/+]mhegazy commentedon Oct 11, 2017
the analysis of module imports in .js files is limited to the known
requirecall.require.mainis not a pattern the compiler looks for. it is also early in the compilation process to know thatrequire.main.requireis an alias torequire.This is currently a design limitation.
weswigham commentedon Oct 11, 2017
Mohamed Hegazy (@mhegazy) Worse yet,
require.main.requireisn't strictly an alias to require - it's a require relative to the package entrypoint... Something we don't currently define.rafaelmaeuer commentedon Jul 24, 2018
I am looking forward to this feature too. Intellisense is not able to understand
require.main.requireas alias forrequire. But this method helps a lot for readability of code when you have files in deeper folder structures.TheColorRed commentedon Jun 1, 2019
I am not sure if this is the same issue, but what I want is to have the types in the current package, but I want the root package to include 'mongodb'.
When I do the following:
I get the following error:
However, the following works, but isn't what I want:
phramos07 commentedon Apr 13, 2020
Apparently
require.main.requireis referencing the Main package of your program, i. e., the entry script. When running with vscode code & debug tool, this package appears to be something else rather than my node js main process, because it fails to find the modulerequireinside themain.