watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 668 forks source link

Webpack example fails to compile #1054

Closed maclean-stu closed 4 years ago

maclean-stu commented 4 years ago

Using the code from the webpack example here https://github.com/watson-developer-cloud/node-sdk/tree/master/examples/webpack I get a failed to compile error

ERROR in ./node_modules/stack-utils/index.js Module not found: Error: Can't resolve 'module' in '/Users/sjm/Box Sync/Demos/app-stt-test/node_modules/stack-utils' @ ./node_modules/stack-utils/index.js 6:2-19 @ ./node_modules/jest-message-util/build/index.js @ ./node_modules/expect/build/toThrowMatchers.js @ ./node_modules/expect/build/index.js @ ./node_modules/ibm-cloud-sdk-core/lib/sdk-test-helpers.js @ ./node_modules/ibm-cloud-sdk-core/index.js @ ./node_modules/ibm-watson/tone-analyzer/v3.js @ ./public/client.js ℹ 「wdm」: Failed to compile.

maclean-stu commented 4 years ago

Working with @apaparazzi0329 he determined that we needed to add an additional configuration in the node: section of the webpack configuration file. eg

'use strict';

module.exports = { mode: 'development', entry: './public/client.js', output: { filename: 'bundle.js', }, node: { // see http://webpack.github.io/docs/configuration.html#node // and https://webpack.js.org/configuration/node/ fs: 'empty', net: 'empty', tls: 'empty', module: 'empty' }, };

maclean-stu commented 4 years ago

The above corrected the issue as per the example. Doco should be updated. However it only works for the '2016-05-19' version of the tone api. It fails if I try and use the current version of the api '2017-09-21'. This should be a defect as customers using these examples will generally use the current version of the api.

apaparazzi0329 commented 4 years ago

The example does in fact work with the current version of the api and the confusion was from different response definitions from the differing versions

maclean-stu commented 4 years ago

Yep, more text did the trick....