Serverless-webpack: invoke local "The webpack plugin could not find the configuration file"

Created on 5 Jun 2019  Â·  12Comments  Â·  Source: serverless-heaven/serverless-webpack

This is a (Bug Report)

Description

serverless invoke local -f <functionName> doesn't work

For bug reports:

  • What went wrong?
    A few weird errors occur:
  1. It says that more than one matching handler is found
  2. It is looking in the wrong place for the webpack.config.js file which is located at ./webpack.config.js
  • What did you expect should have happened?
    serverless invoke local should work in a project that functions correctly with serverless-offline

  • What was the config you used?

service: api
package:
  individually: true
provider:
  name: aws
  runtime: provided
  stage: "${opt:stage, 'local'}"
  region: us-east-1
  environment:
    DEBUG: '*,-babel,-babel:config:*'
    SLS_DEBUG: '*'
functions:
  test:
    handler: src/jobs/test.handler
    layers: # add layer
      - arn:aws:lambda:us-east-1:553035198032:layer:nodejs10:13
plugins:
  - serverless-webpack
  - serverless-offline
custom:
  serverless-offline:
    host: 0.0.0.0
    port: 8080
    providedRuntime: nodejs10
  webpack:
    webpackConfig: 'webpack.config.js'
    packager: 'yarn'
    includeModules: true
  • What stacktrace or error message from your provider did you see?

    The webpack plugin could not find the configuration file at: /Users/user/work/project/api/.webpack/test/webpack.config.js

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you're using:
    v5.3.0
  • Webpack version you're using:
    v4.33.0
  • Serverless Framework Version you're using:
    v1.44.1
  • Operating System:
    macOS 10.14.5 (18F132)
  • Stack Trace (if available):
$ serverless invoke local -f test
Serverless: Invoke webpack:validate
Serverless: Invoke webpack:compile
Serverless: Bundling with Webpack...
Time: 269ms
Built at: 06/05/2019 1:57:53 PM
               Asset      Size         Chunks             Chunk Names
    src/jobs/test.js  4.07 KiB  src/jobs/test  [emitted]  src/jobs/test
src/jobs/test.js.map  3.86 KiB  src/jobs/test  [emitted]  src/jobs/test
Entrypoint src/jobs/test = src/jobs/test.js src/jobs/test.js.map
[./src/jobs/test.ts] 89 bytes {src/jobs/test} [built]
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Invoke webpack:validate
Serverless: WARNING: More than one matching handlers found for 'src/jobs/test'. Using 'src/jobs/test.js'.

  Serverless Error ---------------------------------------

  The webpack plugin could not find the configuration file at: /Users/user/work/project/api/.webpack/test/webpack.config.js

  Stack Trace --------------------------------------------

ServerlessError: The webpack plugin could not find the configuration file at: /Users/user/work/project/api/.webpack/test/webpack.config.js
    at ServerlessWebpack.validate (/Users/user/work/project/api/node_modules/serverless-webpack/lib/validate.js:111:33)
    at ServerlessWebpack.tryCatcher (/Users/user/work/project/api/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/user/work/project/api/node_modules/bluebird/js/release/promise.js:517:31)
    at Promise._settlePromise (/Users/user/work/project/api/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromiseCtx (/Users/user/work/project/api/node_modules/bluebird/js/release/promise.js:611:10)
    at _drainQueueStep (/Users/user/work/project/api/node_modules/bluebird/js/release/async.js:142:12)
    at _drainQueue (/Users/user/work/project/api/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/Users/user/work/project/api/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/user/work/project/api/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     OS:                     darwin
     Node Version:           10.15.3
     Serverless Version:     1.44.1

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Most helpful comment

bump?

All 12 comments

It looks like webpack:validate is invoked twice. Is this expected behavior?

Yes, but it looks more irritating that it tries to find a webpack.config.js
within the .webpack folder instead of the project root.
Can you try to remove the webpackConfig option from your project file (it
is the default anyway), or set it to a relative path
based on the project root if it is located anywhere else?

On Wed, Jun 5, 2019 at 9:42 PM Ethan Setnik notifications@github.com
wrote:

It looks like webpack:validate is invoked twice. Is this expected
behavior?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/serverless-heaven/serverless-webpack/issues/511?email_source=notifications&email_token=ABKEZXV6ZAZBKHH67KKQYJLPZAJMDA5CNFSM4HUCCM72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXAZTKY#issuecomment-499227051,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABKEZXTLBWROHBUIZTIV52DPZAJMDANCNFSM4HUCCM7Q
.

Yes unfortunately I've tried removing both the override webpackConfig as well as changing it's path. But the problem is that the path is actually correct so if I change it's path then the first webpack:validate fails.

I stepped through the validate logic in the debugger and found some strange things:
In the second validate call the reason there is a warning about multiple handlers found is that it's picking up the test.js.map file generated by webpack. concat is used to append the original array of files to the sorted filtered array of files with preferred extensions. So the.map file is appended.
https://github.com/serverless-heaven/serverless-webpack/blob/master/lib/validate.js#L57

The reason for this is that it's looking in:
this.serverless.config.servicePath which changes between the first call to validate and the second call to validate. During local invocation the service path is the path of the built product (which does not contain a webpack.config.js file and thus fails the second validation pass.

Also of note this issue still occurs if I use the --no-build option, e.g. if I first run serverless webpack (whcih runs fine and generates a working product) and then serverless local invoke --no-build -f test (which fails to find the webpack.config.js in the built service directory).

Can anyone help with this? I'm still unable to make it work.

@HyperBrain do you intend to look into this further? Since serverless-offline-scheduler relies on serverless local invoke it has also broken the functionality of this plugin.

This issue also causes [email protected] to no longer be compatible with serverless-webpack

See https://github.com/ajmath/serverless-offline-scheduler/issues/29

@serverless-heaven/serverless-webpack-team @serverless-heaven/serverless-webpack-contributors , can anyone have a look here?

@HyperBrain I traced this issue to my usage of runtime: provided. It should be documented that provided layers won't work for local invoke. See https://github.com/serverless/serverless/issues/5542

Check out https://github.com/esetnik/serverless-webpack/tree/typescript-example-babel-loader-runtime-provided for an example project which demonstrates the issue.

cd examples/typescript && yarn && ./node_modules/.bin/serverless invoke local -f goodbye --stage local

bump?

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitttttten picture bitttttten  Â·  4Comments

bebbi picture bebbi  Â·  3Comments

agreea picture agreea  Â·  3Comments

onhate picture onhate  Â·  5Comments

serverlesspolska picture serverlesspolska  Â·  4Comments