question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

V3: Invoke lokally does not have access to files bundled with the file-loader

See original GitHub issue

Bug Report

Description

I have a sample-file.yaml file I want to bundle this together with my lambda function using file-loader. Executing locally with sls webpack invoke -f test does not have this bundled file in it’s environment. It is bundled to upload for aws though.

Additional Data

Minimal failing example on github

  • Serverless-Webpack Version 2.2.0 and 3.0.0 branches
  • Webpack version: 3.4.1
  • Serverless Framework Version: 1.19.0
  • Operating System: linux

Stack Trace

$ sls webpack invoke -f test
{ handler: './handler.js' }
Serverless: Bundling with Webpack...
Time: 2892ms
                                Asset      Size  Chunks             Chunk Names
59ca0efa9f5633cb0371bbc0355478d8.yaml  13 bytes          [emitted]  
                           handler.js   3.21 kB       0  [emitted]  main
   [0] ./handler.js 183 bytes {0} [built]
   [1] external "fs" 42 bytes {0} [not cacheable]
   [2] ./sample-file.yaml 83 bytes {0} [built]
Serverless: Run function test...
 
  Error --------------------------------------------------
 
  ENOENT: no such file or directory, open '59ca0efa9f5633cb0371bbc0355478d8.yaml'
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                     linux
     Node Version:           6.11.1
     Serverless Version:     1.19.0
 

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jonnysampscommented, Mar 25, 2019

I believe this is happening again. serverless-webpack 5.1.1

0reactions
scriptifycommented, Feb 18, 2020

I temporarily fixed it like this:

function getStaticFilePath(pathToFile: string) {
  const devPath = path.join(process.cwd(), '.webpack', 'service', pathToFile);
  const prodPath = path.join(__dirname, pathToFile);
  return process.env.NODE_ENV === 'production' ? prodPath : devPath;
}

Where pathToFile either comes from a require statement or is a hardcoded path provided by you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

file-loader - webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Webpack file-loader outputs [object Module] - Stack Overflow
I get no errors. Here is my webpack configuration and index.html . const projectRoot = path.resolve(__dirname, ...
Read more >
Resolve "ClassNotFoundExeption" errors from Java Lambda ...
The ClassNotFoundException error occurs when a Java runtime loads a class by its fully qualified name, but doesn't locate the class.
Read more >
Esbuild - Serverless Framework: Plugins
serverless-esbuild. Serverless plugin for zero-config JavaScript and TypeScript code bundling using promising fast & furious esbuild bundler and minifier.
Read more >
Writing a custom webpack loader - Redd Developer
mp3 files. Using a custom loader. There are two ways to use a loader: tell webpack to resolve it from a local file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found