aws / aws-iot-device-sdk-js

SDK for connecting to AWS IoT from a device using JavaScript/Node.js
Apache License 2.0
964 stars 384 forks source link

require('aws-iot-device-sdk'); with React and Webpack .... #197

Closed jamesladd closed 6 years ago

jamesladd commented 6 years ago

Hi Aws Iot Team,

Brilliant piece of work on the SDK.

I have recently moved my project that makes use of the SDK without webpack to one that uses webpack.

My problem is that the webpack build of the project is getting errors when trying to 'package' the SDK.

I tried the instructions for building with webpack but that isn't working for me. I get the following errors:

ERROR in ./node_modules/aws-iot-device-sdk/common/lib/tls-reader.js Module not found: Error: Can't resolve 'fs' in '/home/jamesl/dev/react-boilerplate/node_modules/aws-iot-device-sdk/common/lib' @ ./node_modules/aws-iot-device-sdk/common/lib/tls-reader.js 17:14-27 @ ./node_modules/aws-iot-device-sdk/device/index.js @ ./node_modules/aws-iot-device-sdk/index.js @ dll reactBoilerplateDeps

ERROR in ./node_modules/aws-iot-device-sdk/device/index.js Module not found: Error: Can't resolve 'fs' in '/home/jamesl/dev/react-boilerplate/node_modules/aws-iot-device-sdk/device' @ ./node_modules/aws-iot-device-sdk/device/index.js 29:9-22 @ ./node_modules/aws-iot-device-sdk/index.js @ dll reactBoilerplateDeps

ERROR in ./node_modules/aws-iot-device-sdk/device/lib/tls.js Module not found: Error: Can't resolve 'tls' in '/home/jamesl/dev/react-boilerplate/node_modules/aws-iot-device-sdk/device/lib' @ ./node_modules/aws-iot-device-sdk/device/lib/tls.js 17:10-24 @ ./node_modules/aws-iot-device-sdk/device/index.js @ ./node_modules/aws-iot-device-sdk/index.js @ dll reactBoilerplateDeps

I'm really not sure what to do with webpack to make this work. Please help - I'm pulling out my hair and exhausting my google skills.

jamesladd commented 6 years ago

I have fixed this (at least it appears fixed)

In the webpack/webpack.base.babel.js I added the following line:

node: { fs: 'empty', tls: 'empty' },

Directly before the "modules" element. Eg:

node: { fs: 'empty', tls: 'empty' }, module: {

Now webpack is not returning errors from a "npm run build:dll" like it was.

I have an

import awsIot from 'aws-iot-device-sdk';

That is working.

I hope this helps others.