serverless-webpack can't resolve module

3.8k views Asked by At

Getting this error from serverless-webpack:

ERROR in ../db/actions/index.js
Module not found: Error: Can't resolve 'amazon-dax-client' in '/var/task/db/actions'
 @ ../db/actions/index.js 2:24-52
 @ ../db/db.js
 @ ./crop.js

My webpack.config.js file contains:

const slsw = require('serverless-webpack')

module.exports = {
    entry: slsw.lib.entries,
    target: 'node',
    externals: {
        sharp: 'commonjs sharp',
    },
    // Run babel on all .js files and skip those in node_modules
    module: {
        rules: [{
            test: /\.js$/,
            loader: 'babel-loader',
            include: __dirname,
            exclude: /node_modules/,
        }]
    }
}

The amazon-dax-client module is present in node_modules.

I've rolled back to the last versions of webpack and serverless-webpack that worked for me:

"serverless-webpack": "4.3.0",
"webpack": "3.11.0"

Any ideas on how to resolve or to get additional logging output to track down the issue?

3

There are 3 answers

2
Aaron On

Can you try removing the /node_modules/ exclusion? If that's removed, I'd imagine it'd be able to get into that folder and do what you need. Since amazon-dax-client is in that folder, and you're telling webpack to ignore the node_modules folder, it won't be able to reach it. Let me know if that helps.

0
genestd On

I'm no longer getting the error, although I can't say specifically what fixed it. Deleting package-lock.json and node_modules seemed to be the catalyst.

0
sarp On

Alternatively, you may consider using node-prune to remove unnecessary files from node_modules (.md, .ts, ...) It would not be as effective as webpack but it's way less complicated and definitely not error-prone. It can be good enough for certain projects.