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.

Cannot find module with serverless-offline (looking in .build/.webpack instead of .webpack)

See original GitHub issue

This is a (Bug Report)

Description

For bug reports:

  • What went wrong? I am using serverless-webpack with typescript and want to use serverless-offline everything compile and run properly, but when try to call the handler through API route, noticed the path it referring is wrong.

offline: Failure: Cannot find module '/Users/nader/Projects/company/4m-bamboohr-xero-integration/.build/.webpack/service/src/functions/approved-leaves/getTimeOffRequests'

  • What did you expect should have happened? expected it to be offline: Failure: Cannot find module '/Users/nader/Projects/company/4m-bamboohr-xero-integration/.webpack/service/src/functions/approved-leaves/getTimeOffRequests'

  • What was the config you used? webpack config

mode: isLocal ? 'development' : 'production',
  entry: slsw.lib.entries,
  devtool: isLocal ? 'cheap-module-eval-source-map' : 'source-map',
  resolve: {
    extensions: ['.mjs', '.json', '.ts'],
    symlinks: false,
    cacheWithContext: false,
  },
  output: {
    devtoolModuleFilenameTemplate: '[absolute-resource-path]',
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },

tsconfig

  "compilerOptions": {
    "lib": ["es2017"],
    "module": "commonjs",
    "removeComments": true,
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "target": "es2017",
    "outDir": ".build",
    "sourceRoot": "/",
    "rootDir": "./src"
  },

Similar or dependent issue(s):

Additional Data

  • Serverless-Webpack Version you’re using: 5.3.2
  • Webpack version you’re using:4.29.0
  • Serverless Framework Version you’re using:1.74.1
  • Operating System: macOS
  • Stack Trace (if available):

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
LukaszKucielcommented, Jul 30, 2020

@nitronaj I fixed this by removing serverless-plugin-typescript and leaving serverless-webpack alone. If you think of it you don’t need both because you compile the code with webpack. So when you are using both these plugins typescript code is compiled by both and there is some mess created.

1reaction
rnnyrkcommented, Jun 11, 2021

Thanks @LukaszKuciel took me waaay too long to find this thread

Read more comments on GitHub >

github_iconTop Results From Across the Web

serverless-webpack - npm
A Serverless Framework plugin to build your lambda functions with Webpack. This plugin is for you if you want to use the latest...
Read more >
aws + serverless + webpack => cannot find module xxx in prod
One possible solution to the error is to remove the src/ from the handler of the function in serverless.yml file. This approach has...
Read more >
serverless-offline/community - Gitter
Hi all, I'm getting a MODULE_NOT_FOUND error from InProcessRunner.js when trying to use Lambda#invoke on another function running in my serverless offline ...
Read more >
Serverless Webpack in Lambda Simplified 101 - Learn | Hevo
This blog explains the different aspects of Serverless Webpack in Lambda. In addition to that, it describes AWS Lambda as well.
Read more >
Setting up a Serverless Project with Webpack, Babel, and Knex
The solution I went for is to use a Babel plugin to transform ESM to CommonJS Modules which is the standard for Node...
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