I'm trying to bundle and run a TypeScript project using Webpack. One of the TypeScript files requires and external node depenedency. Webpack bundles the file without problem, but when I try to run it on the browser it gives me the following error.

webpack.config.js
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: './src/index.ts',
resolve: {
extensions: [
'.js',
'.jsx',
'.json',
'.ts',
'.tsx'
]
},
externals: [nodeExternals()],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'web',
module: {
loaders: [
{ test: /\.ts(x?)$/, loader: 'ts-loader' },
],
},
};
External node dependency aws-iot-device-sdk
Can someone help me with this?
Update: Found that the following line in the TypeScript file causes the issue. is there a work-around for this?
const client = new IoTClient(true, IoTClientOptions);
As you are using
require('path');
you have to download RequireJS
Here
RequireJS is a JavaScript file and module loader.
or add Add http://requirejs.org/docs/release/2.2.0/minified/require.js to your project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With