Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoke local "The webpack plugin could not find the configuration file" #511

Closed
esetnik opened this issue Jun 5, 2019 · 23 comments
Closed
Labels
awaiting reply Awaiting for a reply from the OP

Comments

@esetnik
Copy link
Contributor

esetnik commented Jun 5, 2019

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.
@esetnik
Copy link
Contributor Author

esetnik commented Jun 5, 2019

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

@HyperBrain
Copy link
Member

HyperBrain commented Jun 6, 2019 via email

@esetnik
Copy link
Contributor Author

esetnik commented Jun 6, 2019

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.

@esetnik
Copy link
Contributor Author

esetnik commented Jun 6, 2019

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).

@esetnik
Copy link
Contributor Author

esetnik commented Jun 20, 2019

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

@esetnik
Copy link
Contributor Author

esetnik commented Jul 16, 2019

@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.

@esetnik
Copy link
Contributor Author

esetnik commented Jul 18, 2019

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

See ajmath/serverless-offline-scheduler#29

@HyperBrain
Copy link
Member

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

@esetnik
Copy link
Contributor Author

esetnik commented Jul 30, 2019

@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 serverless/serverless#5542

@esetnik
Copy link
Contributor Author

esetnik commented Jul 30, 2019

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

@tsaodown
Copy link

bump?

@ggmartins
Copy link

+1

@bugb
Copy link

bugb commented Nov 10, 2021

I ended up with create two serverless files, one for developing in local (using serverless offline, typescript) and one for deploy (using webpack plugin)

@vicary
Copy link
Member

vicary commented Nov 10, 2021

@bugb Would you mind providing a minimum reproducing repo?

@vicary vicary added the awaiting reply Awaiting for a reply from the OP label Nov 10, 2021
@bugb
Copy link

bugb commented Nov 10, 2021

@vicary sure, I will update it in the next 2-3 hours, time for my dinner

@serverless-heaven serverless-heaven deleted a comment from bugb Nov 10, 2021
@vicary
Copy link
Member

vicary commented Nov 19, 2021

@bugb Not sure if I misunderstood, a quick run of serverless webpack --config serverless.deploy.yml in goserverless/serverless-typescript-example@1e38b58 yields a successful build.

image

I don't see the error mentioned by the op in your pipelines too.

@bugb
Copy link

bugb commented Nov 19, 2021

@vicary , yes I have to make my code works, I mean I need to use 2 separated files serverless.deploy.yml (for deploying) and serverless.local.yml (for local development) because in local development the plugin serverless-webpack does not work well with serverless-offline, error:

"The webpack plugin could not find the configuration file"

@vicary
Copy link
Member

vicary commented Nov 19, 2021

Reducing your handler to a minimal, it is working without problem.

image

I happened to produce a similar error when using serverless-webpack in tandem with serverless-plugin-typescript, if that's actually the case, this is not related to serverless-offline and is not supported.

@j0k3r j0k3r closed this as completed Mar 24, 2022
@softmarshmallow
Copy link

Whats the solution here? what causes this problem?

@vicary
Copy link
Member

vicary commented May 12, 2022

@softmarshmallow See my last comment #511 (comment) for context.

If you believe you are facing a different problem, please open a new issue.

@bugb
Copy link

bugb commented May 13, 2022

Whats the solution here? what causes this problem?

you can also check my repo here for an example: https://github.com/goserverless/serverless-typescript-example/releases/tag/v1.0.5

@httpiga
Copy link

httpiga commented May 19, 2022

UPDATE: as stated in this comment, serverless-plugin-typescript is not needed when using serverless-webpack.


I happened to produce a similar error when using serverless-webpack in tandem with serverless-plugin-typescript, if that's actually the case, this is not related to serverless-offline and is not supported.

I found out that the order the plugins that appear in serverless.yml matters in these cases, in particular using

plugins:
    - serverless-webpack
    # - serverless-webpack-prisma (eventually)
    - serverless-plugin-typescript
    - serverless-offline

permits to compile without any errors.

The importance of the order is reported in the serverless-plugin-typescript docs page, but ignored in other pages. Could be useful to mention this across all the plugin doc pages that may be involved in this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply Awaiting for a reply from the OP
Projects
None yet
Development

No branches or pull requests

9 participants