@@ -51,6 +51,7 @@ import {
51
51
parseBuildErrorStack ,
52
52
parseNpmInstallError ,
53
53
} from "../utilities/deployErrors" ;
54
+ import { findUp , pathExists } from "find-up" ;
54
55
55
56
let apiClient : CliApiClient | undefined ;
56
57
@@ -465,7 +466,7 @@ function useDev({
465
466
const environmentVariablesResponse =
466
467
await environmentClient . getEnvironmentVariables ( config . project ) ;
467
468
468
- const processEnv = gatherProcessEnv ( ) ;
469
+ const processEnv = await gatherProcessEnv ( ) ;
469
470
470
471
const backgroundWorker = new BackgroundWorker ( fullPath , {
471
472
projectConfig : config ,
@@ -775,7 +776,7 @@ function createDuplicateTaskIdOutputErrorMessage(
775
776
return `Duplicate ${ chalkTask ( "task id" ) } detected:${ duplicateTable } ` ;
776
777
}
777
778
778
- function gatherProcessEnv ( ) {
779
+ async function gatherProcessEnv ( ) {
779
780
const env = {
780
781
NODE_ENV : process . env . NODE_ENV ?? "development" ,
781
782
PATH : process . env . PATH ,
@@ -786,11 +787,44 @@ function gatherProcessEnv() {
786
787
NVM_BIN : process . env . NVM_BIN ,
787
788
LANG : process . env . LANG ,
788
789
TERM : process . env . TERM ,
789
- NODE_PATH : process . env . NODE_PATH ,
790
+ NODE_PATH : await amendNodePathWithPnpmNodeModules ( process . env . NODE_PATH ) ,
790
791
HOME : process . env . HOME ,
791
792
BUN_INSTALL : process . env . BUN_INSTALL ,
792
793
} ;
793
794
794
795
// Filter out undefined values
795
796
return Object . fromEntries ( Object . entries ( env ) . filter ( ( [ key , value ] ) => value !== undefined ) ) ;
796
797
}
798
+
799
+ async function amendNodePathWithPnpmNodeModules ( nodePath ?: string ) : Promise < string | undefined > {
800
+ const pnpmModulesPath = await findPnpmNodeModulesPath ( ) ;
801
+
802
+ if ( ! pnpmModulesPath ) {
803
+ return nodePath ;
804
+ }
805
+
806
+ if ( nodePath ) {
807
+ if ( nodePath . includes ( pnpmModulesPath ) ) {
808
+ return nodePath ;
809
+ }
810
+
811
+ return `${ nodePath } :${ pnpmModulesPath } ` ;
812
+ }
813
+
814
+ return pnpmModulesPath ;
815
+ }
816
+
817
+ async function findPnpmNodeModulesPath ( ) : Promise < string | undefined > {
818
+ return await findUp (
819
+ async ( directory ) => {
820
+ const pnpmModules = join ( directory , "node_modules" , ".pnpm" , "node_modules" ) ;
821
+
822
+ const hasPnpmNodeModules = await pathExists ( pnpmModules ) ;
823
+
824
+ if ( hasPnpmNodeModules ) {
825
+ return pnpmModules ;
826
+ }
827
+ } ,
828
+ { type : "directory" }
829
+ ) ;
830
+ }
0 commit comments