Pathing with subdir not working as expected: Unable to import module
vikre opened this issue · comments
Hi,
I'm having trouble using this plugin when it comes to what it does with pathing when it optimizes the code I think.
Using serverless v1.37.0 and serverless-plugin-optimize v4.0.2-rc.1
My code is structured like this:
- serverless.yml
- package.json
- functions/
- app.js <- handler
- gdl/
- a.js
- b.js
- c.js
And in my serverless.yaml
-file (the relevant sections) looks like this:
package:
individually: true
exclude:
- ./**
- '!node_modules/**'
functions:
assistant:
handler: functions/app.handler
Im getting the following error when I try to trigger the app after deploying it to aws:
Unable to import module '_optimize/assistant-service-test-assistant/functions/app'
I have debugged a bit and if I do a console.log
on the path inside app.js
it prints the following
app path /var/task/_optimize/assistant-service-test-assistant/functions/functions/app.js
As you can see, it have an extra /functions
in the path, so it makes sense that it can't find module.. Someone that can help me with this issue?
Just for fun - If I put the app.js
in the gdl
-folder I get
app path /var/task/_optimize/assistant-service-test-assistant/functions/gdl/functions/gdl/app.js
which suggests that something strange is happening when the app is optimized.
The debug output:
Serverless: Optimize: debug {
"functions": [
{
"bundle": "<userDir>/dev/gdl/assistant-service/_optimize/assistant-service-test-assistant/functions/app.js",
"handlerOriginal": "functions/app.handler",
"handlerOptimize": "_optimize/assistant-service-test-assistant/functions/app.handler",
"package": {
"exclude": [
"**"
],
"include": [
"_optimize/assistant-service-test-assistant/**"
]
}
}
],
"options": {
"debug": true,
"exclude": [
"aws-sdk"
],
"external": [],
"externalPaths": {},
"extensions": [],
"global": false,
"includePaths": [],
"ignore": [],
"minify": true,
"plugins": [],
"prefix": "_optimize",
"presets": [
[
"<userDir>/dev/gdl/assistant-service/node_modules/@babel/preset-env/lib/index.js",
{
"targets": {
"node": "8.10"
}
}
]
],
"individually": true
}
}