Skip to content

Commit 67b26ae

Browse files
committed
Fix paths for Docker on Windows
When using on Windows with the default docker configuration, it passes `.serverless\\requirements.txt` to `docker ... pip install ...`. This results in the following error: ``` Could not open requirements file: [Errno 22] Invalid argument: '.serverless\\requirements.txt' ``` To fix this, we can convert the paths from Windows style to Linux style when running on Windows with `dockerZip: true`.
1 parent bab1f9f commit 67b26ae

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/pip.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function installRequirements(requirementsPath, targetFolder, serverless, service
4040
let cmdOptions;
4141
let pipCmd = [
4242
options.pythonBin, '-m', 'pip', '--isolated', 'install',
43-
'-t', targetRequirementsFolder, '-r', fileName,
43+
'-t', dockerPathForWin(options, targetRequirementsFolder), '-r', dockerPathForWin(options, fileName),
4444
...options.pipCmdExtraArgs,
4545
];
4646
if (!options.dockerizePip) {
@@ -122,6 +122,13 @@ function installRequirements(requirementsPath, targetFolder, serverless, service
122122
}
123123
};
124124

125+
function dockerPathForWin(options, path) {
126+
if (process.platform === 'win32' && options.dockerizePip) {
127+
return path.replace('\\', '/');
128+
}
129+
return path;
130+
}
131+
125132
/**
126133
* pip install the requirements to the .serverless/requirements directory
127134
* @return {undefined}

0 commit comments

Comments
 (0)