serverless-webpack: sls invoke local causing rewriting .webpack directory
This is a Bug Report
Description
I have the following serverless.yml:
# NOTE: update this with your service name
service: lanti-serverless-stack-api
frameworkVersion: "=1.27.1"
# Use the serverless-webpack plugin to transpile ES6
plugins:
- serverless-webpack
- serverless-dynamodb-local
- serverless-offline #serverless-offline needs to be last in the list
# serverless-webpack configuration
# Enable auto-packing of external modules
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
packager: yarn
stage: ${opt:stage, self:provider.stage}
DB_PREFIX: ${file(./env.yml):${self:custom.stage}.DB_PREFIX}
dynamodb:
start:
port: 8000
inMemory: true
migrate: true
seed: true
seed:
domain:
sources:
- table: notes
sources: [./offline/migrations/todo-seed.json]
resources:
Resources: ${file(offline/migrations/todo.yml)}
package:
individually: true
exclude:
- node_modules/dynamodb-localhost/**
- node_modules/serverless-dynamodb-local/**
- node_modules/serverless-offline/**
provider:
name: aws
runtime: nodejs8.10
profile: serverless
stage: dev
region: us-east-1
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource:
- "arn:aws:dynamodb:*:*"
environment:
APP_SECRET: ${file(./env.yml):${self:custom.stage}.APP_SECRET}
DB_PREFIX: ${file(./env.yml):${self:custom.stage}.DB_PREFIX}
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
cors: true
create:
handler: lambdas/create.main
events:
- http:
path: notes
method: post
cors: true
authorizer: aws_iam
get:
handler: lambdas/get.main
events:
- http:
path: notes/{id}
method: get
cors: true
authorizer: aws_iam
list:
handler: lambdas/list.main
events:
- http:
path: notes
method: get
cors: true
authorizer: aws_iam
update:
handler: lambdas/update.main
events:
- http:
path: notes/{id}
method: put
cors: true
authorizer: aws_iam
delete:
handler: lambdas/delete.main
events:
- http:
path: notes/{id}
method: delete
cors: true
authorizer: aws_iam
This is my webpack.config.js:
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: slsw.lib.entries,
target: 'node',
// Generate sourcemaps for proper error messages
devtool: 'source-map',
// Since 'aws-sdk' is not compatible with webpack,
// we exclude all node dependencies
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
optimization: {
// We no not want to minimize our code.
minimize: false,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
// Run babel on all .js files and skip those in node_modules
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: __dirname,
exclude: /node_modules/,
},
],
},
};
When I try to run the following command:
$ SET SLS_DEBUG=* && sls invoke local --function create --path mocks/create-event.json
It’s halting the server, because re-writing the entire folder with the one create function only:
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command webpack
Serverless: Load command dynamodb
Serverless: Load command dynamodb:migrate
Serverless: Load command dynamodb:seed
Serverless: Load command dynamodb:start
Serverless: Load command dynamodb:noStart
Serverless: Load command dynamodb:remove
Serverless: Load command dynamodb:install
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke invoke:local
Serverless: Invoke webpack:validate
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Time: 2157ms
Built at: 2018-05-05 22:02:57
Asset Size Chunks Chunk Names
lambdas/create.js 9.69 KiB lambdas/create [emitted] lambdas/create
lambdas/create.js.map 8.34 KiB lambdas/create [emitted] lambdas/create
Entrypoint lambdas/create = lambdas/create.js lambdas/create.js.map
[./lambdas/create.js] 2.34 KiB {lambdas/create} [built]
[./libs/dynamodb-lib.js] 754 bytes {lambdas/create} [built]
[./libs/response-lib.js] 840 bytes {lambdas/create} [built]
[aws-sdk] external "aws-sdk" 42 bytes {lambdas/create} [built]
[babel-runtime/core-js/json/stringify] external "babel-runtime/core-js/json/stringify" 42 bytes {lambdas/create} [built]
[babel-runtime/helpers/asyncToGenerator] external "babel-runtime/helpers/asyncToGenerator" 42 bytes {lambdas/create} [built]
[babel-runtime/regenerator] external "babel-runtime/regenerator" 42 bytes {lambdas/create} [built]
[source-map-support/register] external "source-map-support/register" 42 bytes {lambdas/create} [built]
[uuid] external "uuid" 42 bytes {lambdas/create} [built]
{ ResourceNotFoundException: Requested resource not found
at Request.extractError (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\protocol\json.js:48:27)
at Request.callListeners (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
at Request.emit (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
at Request.emit (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:683:14)
at Request.transition (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:22:10)
at AcceptorStateMachine.runTo (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\state_machine.js:14:12)
at D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\state_machine.js:26:10
at Request.<anonymous> (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:38:9)
at Request.<anonymous> (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:685:12)
at Request.callListeners (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\sequential_executor.js:115:18)
at Request.emit (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
at Request.emit (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:683:14)
at Request.transition (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:22:10)
at AcceptorStateMachine.runTo (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\state_machine.js:14:12)
at D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\state_machine.js:26:10
at Request.<anonymous> (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:38:9)
at Request.<anonymous> (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\request.js:685:12)
at Request.callListeners (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\sequential_executor.js:115:18)
at callNextListener (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\sequential_executor.js:95:12)
at IncomingMessage.onEnd (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\aws-sdk\lib\event_listeners.js:269:13)
at IncomingMessage.emit (events.js:187:15)
at IncomingMessage.EventEmitter.emit (domain.js:442:20)
at endReadableNT (_stream_readable.js:1091:14)
at process._tickCallback (internal/process/next_tick.js:174:19)
message: 'Requested resource not found',
code: 'ResourceNotFoundException',
time: 2018-05-05T20:02:59.235Z,
requestId: 'MSHUC9B0RLRIH4TL3J3I52MGQ7VV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 400,
retryable: false,
retryDelay: 9.94491247364846 }
In a normal build, functions presented in .webpack/service folder (handler.js file), and every other function in a lambda subfolder.
If I run this with the --no-build flag, this is what I got:
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command webpack
Serverless: Load command dynamodb
Serverless: Load command dynamodb:migrate
Serverless: Load command dynamodb:seed
Serverless: Load command dynamodb:start
Serverless: Load command dynamodb:noStart
Serverless: Load command dynamodb:remove
Serverless: Load command dynamodb:install
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke invoke:local
Serverless: Invoke webpack:validate
Serverless: Skipping build and using existing compiled output
Error --------------------------------------------------
ENOENT: no such file or directory, chdir 'D:\www\node\serverless\lanti-serverless-stack\api\.webpack\create'
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: ENOENT: no such file or directory, chdir 'D:\www\node\serverless\lanti-serverless-stack\api\.webpack\create'
at process.chdir (C:\Users\User\AppData\Roaming\npm\node_modules\serverless\node_modules\graceful-fs\polyfills.js:21:9)
at process.chdir (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\graceful-fs\polyfills.js:21:9)
at ServerlessWebpack.prepareLocalInvoke (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\serverless-webpack\lib\prepareLocalInvoke.js:24:13)
From previous event:
at Object.before:invoke:local:invoke [as hook] (D:\www\node\serverless\lanti-serverless-stack\api\node_modules\serverless-webpack\index.js:123:10)
at BbPromise.reduce (C:\Users\User\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:372:55)
at runCallback (timers.js:696:18)
at tryOnImmediate (timers.js:667:5)
at processImmediate (timers.js:649:5)
at process.topLevelDomainCallback (domain.js:121:23)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information -----------------------------
OS: win32
Node Version: 10.0.0
Serverless Version: 1.27.1
Similar or dependent issue(s):
- None that I know about.
Additional Data
- Serverless-Webpack Version you’re using: 5.1.5
- Webpack version you’re using: 4.7.0
- Serverless Framework Version you’re using: 1.27.1
- Operating System: Windows 10 v10.0.17134.1
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 20 (9 by maintainers)
What is the status of this issue? I have this problem right now…
I believe I am seeing the same issue. In order to test with serverless-offline I must set
individually: false, otherwise I’ll seeError: ENOENT: no such file or directory, uv_chdirwhen I attempt to invoke a function withserverless invoke local -f functionName --no-build.It’s a minor inconvenience, so long as I remember to set
individually:truewhen I am done.I’ll try to fix it and will open a PR tomorrow that you can use to test.