File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,15 @@ module.exports = function resolve(dirname) {
107107
108108 // If the above didn't work, or this module is loaded globally, then
109109 // resort to require.main.filename (See http://nodejs.org/api/modules.html)
110- if ( alternateMethod || null == appRootPath ) {
111- appRootPath = path . dirname ( requireFunction . main . filename ) ;
110+ if ( ( alternateMethod || null == appRootPath ) ) {
111+ if ( requireFunction . main ) {
112+ appRootPath = path . dirname ( requireFunction . main . filename ) ;
113+ } else {
114+ // This is the case when app-root-path is bundle'd to a commonjs2 format and is being called from an esm file.
115+ // In those cases require.main is undefined (See https://nodejs.org/api/modules.html#accessing-the-main-module)
116+ // At that point we can only get the root from looking at the callee
117+ appRootPath = path . dirname ( process . argv [ 1 ] ) ;
118+ }
112119 }
113120
114121 // Handle global bin/ directory edge-case
You can’t perform that action at this time.
0 commit comments