copyFiles causing error: ERROR in unable to locate...
I have been using serverless-bundle for a while now without any issues. Suddenly, when removing my node_modules folder and running npm install, I am now getting an error. Please see my output below when running serverless offline. I get the same error when running serverless deploy.
Serverless: Invoke offline
Serverless: Invoke webpack:validate
Serverless: Using configuration:
{
"packager": "npm",
"packagerOptions": {},
"webpackConfig": "node_modules\\serverless-bundle/src/webpack.config.js",
"includeModules": {
"forceExclude": [
"aws-sdk"
],
"forceInclude": null,
"packagePath": "package.json"
},
"keepOutputDirectory": false
}
Serverless: Removing C:\Users\Stewart\Desktop\Crux Projects Local\Achievement Awards Group\BountiXP Platform\serverless-api\billing\services\billing-address-api\.webpack
Serverless: Bundling with Webpack...
Serverless: Webpack watch invoke: HASH NEW=cf04d716104492eaef2a CUR=null
LOG from copy-webpack-plugin
<e> unable to locate "C:\Users\Stewart\Desktop\Crux Projects Local\Achievement Awards Group\BountiXP Platform\serverless-api\billing\services\billing-address-api\sql\*" at "C:\Users\Stewart\Desktop\Crux Projects Local\Achievement Awards Group\BountiXP Platform\serverless-api\billing\services\billing-address-api\sql\*"
+ 7 hidden lines
ERROR in unable to locate "C:\Users\Stewart\Desktop\Crux Projects Local\Achievement Awards Group\BountiXP Platform\serverless-api\billing\services\billing-address-api\sql\*" at "C:\Users\Stewart\Desktop\Crux Projects Local\Achievement Awards Group\BountiXP Platform\serverless-api\billing\services\billing-address-api\sql\*"
Here is my package.json:
{
"name": "billing-address-api",
"version": "0.1.0",
"description": "bountixp billing-address api",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "bountixp",
"license": "ISC",
"devDependencies": {
"serverless-bundle": "^3.2.1",
"serverless-offline": "^6.8.0"
}
}
Here is my serverless.yml:
service: billing-address-api
plugins:
- serverless-bundle
- serverless-offline
custom:
bundle:
linting: false
copyFiles: # Copy any additional files to the generated package
- from: 'sql/*'
to: './'
provider:
name: aws
stage: ${opt:stage, 'dev'}
region: eu-west-1
runtime: nodejs12.x
functions:
...
I have tried downgrading to v3.0.0. I've tried removing my package-lock.json file. No changes have been made to my config since it was previously working, only the npm install, so my thoughts are it must be a dependency package issue of some sort. The issue is only on Windows: Windows 10 Version 1903 (OS Build 18362.1139). Works fine on Ubuntu. Issue can be replicated on my developer's PC too.
I've made some progress with this. Everything works fine when the plugin is installed explicitly with npm install serverless-bundle, but when running npm install with the plugin already listed in package.json, the issue arises.
Can you try removing your package lock file and try it an install from scratch?
Thanks for your response. I have tried this with no luck. The only workaround seems to be to remove the plugin and install it again. This is annoying, as every time I do an npm install it breaks again.
That's really weird. Can you create a simple repo with this problem?
I ran into this issue this morning. Any progress or discoveries about it?
I ran into this issue this morning. Any progress or discoveries about it?
The issue is a posix/win32 path problem.
There is no fix from the author yet, so I'm currently using a self-authored patch with patch-package.
Here is my patch: serverless-bundle+5.5.0.patch
diff --git a/node_modules/serverless-bundle/src/webpack.config.js b/node_modules/serverless-bundle/src/webpack.config.js
index f9b1b76..b74ac1b 100644
--- a/node_modules/serverless-bundle/src/webpack.config.js
+++ b/node_modules/serverless-bundle/src/webpack.config.js
@@ -29,7 +29,7 @@ const defaultConfig = importFresh("./config");
const isLocal = slsw.lib.webpack.isLocal;
const aliases = config.options.aliases;
-const servicePath = config.servicePath;
+const servicePath = config.servicePath.replace(/\\/g, "/"); // Fix glob issues by converting the path to posix.
const nodeVersion = config.nodeVersion;
const externals = config.options.externals;
const copyFiles = config.options.copyFiles;
@@ -339,7 +339,7 @@ function plugins() {
return {
to: data.to,
context: servicePath,
- from: path.join(servicePath, data.from),
+ from: path.posix.join(servicePath, data.from), // Fix glob issues by converting the path to posix.
};
}),
})
Note that I'm using version 5.5.0.