0
votes

I am writing an Express application in TypeScript and trying to use webpack to transpile both production code and vendor modules into a single bundle.js file. But I can not do so because of a weird node-pre-gyp error :

Module not found: Error: Can't resolve 'aws-sdk' in '[...]/harema-api/node_modules/bcrypt/node_modules/node-pre-gyp/lib'

I am running node 8.11.2. Here is my webpack.config.js:

const path = require('path');

module.exports = {
    entry: './src/index.ts',
    target: 'node',
    mode: 'production',
    devtool: 'inline-source-map',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader'
            }
        ]
    },
    resolve: {
        extensions: [ '.tsx', '.ts', '.js' ]
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    }
};

Any idea ? Thank you in advance.

2
In my case, the problem was resolved by switching to bcryptjs package instead of bcrypt. A little bit slower, but it works.Oscar Saraza

2 Answers

3
votes

If you're still having this problem, I fixed this by explicitly specifying --config with the webpack command, rather than just using the config as the first argument or omitting it.

Before: webpack ./webpack.config.js --mode production // ERROR: Unable to resolve ...

After: webpack --config ./webpack.config.js --mode production

I admit I'm not certain why this addressed the problem as in my case it was reading the config file either way. I'm using webpack v4.16.2 and webpack-cli v3.1.0.

3
votes

I added the package and error has disapeared, however it added 4.5MB (!) to my package.

Deleting the whole 'node_modules' folder and 'npm install' solved the problem.