Overview
With the latest ibm-watson 6.2.1 version, when bundling JavaScript, using tools such as Webpack or Rollup.js, a runtime error occurs. The exception message received when running the bundled file is as follows: "Class constructor BaseService cannot be invoked without 'new'". We have narrowed the issue down to the fact that when the ibm-cloud-sdk-core 2.17.0 or older child dependency is used, the error does not occur. When the latest child dependency ibm-cloud-sdk-core: 2.17.5 is used, the exception does occur. The 6.1.1 & 6.2.1 versions do not throw an error, when using the ibm-cloud-sdk-core 2.17.0 child dependency.
Expected behavior
The ibm-watson packages should be capable of being bundled using the current 6.2.1 version of the ibm-watson package.
Actual behavior
When a bundled file is generated using the latest ibm-watson version, the Class constructor BaseService cannot be invoked without 'new' occurs during runtime when creating a new SpeechToTextV1. We also see the same issue when creating a new Watson Assistant.
How to reproduce
1.) Clone the following repository (https://github.com/bwilloughby1/watson-base-service-error)
2.) From the root directory run npm install
3.) From the root directory run npm run build
4.) Run the bundled app.js using node ./dist/app.js
5.) The following error will occur:
SDK Versionibm-watson 6.2.1
Additional information:
Windows 10 & Ubuntu 20.04
VS Code 1.63.0
Which version of Node are you using?
Node 14.18.2 & 16.13.1
Additional context
When using Rollup.js we received a more detailed warning message on build that may be helpful:
src/app.local.ts → output...
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
node_modules/ibm-cloud-sdk-core/es/lib/request-wrapper.js
1: /* eslint-disable class-methods-use-this */
2: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
^
3: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4: return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence
node_modules/ibm-cloud-sdk-core/es/auth/token-managers/container-token-manager.js
14: * limitations under the License.
15: */
16: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
^
17: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18: return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence
node_modules/ibm-cloud-sdk-core/es/auth/token-managers/vpc-instance-token-manager.js
14: * limitations under the License.
15: */
16: var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
^
17: function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18: return new (P || (P = Promise))(function (resolve, reject) {
...and 1 other occurrence
Overview With the latest
ibm-watson
6.2.1 version, when bundling JavaScript, using tools such as Webpack or Rollup.js, a runtime error occurs. The exception message received when running the bundled file is as follows: "Class constructor BaseService cannot be invoked without 'new'". We have narrowed the issue down to the fact that when theibm-cloud-sdk-core
2.17.0 or older child dependency is used, the error does not occur. When the latest child dependency ibm-cloud-sdk-core: 2.17.5 is used, the exception does occur. The 6.1.1 & 6.2.1 versions do not throw an error, when using theibm-cloud-sdk-core
2.17.0 child dependency.Expected behavior The ibm-watson packages should be capable of being bundled using the current 6.2.1 version of the ibm-watson package.
Actual behavior When a bundled file is generated using the latest ibm-watson version, the
Class constructor BaseService cannot be invoked without 'new'
occurs during runtime when creating a new SpeechToTextV1. We also see the same issue when creating a new Watson Assistant.How to reproduce 1.) Clone the following repository (https://github.com/bwilloughby1/watson-base-service-error) 2.) From the root directory run
npm install
3.) From the root directory runnpm run build
4.) Run the bundled app.js usingnode ./dist/app.js
5.) The following error will occur:SDK Version
ibm-watson
6.2.1Additional information:
Which version of
Node
are you using?Additional context When using Rollup.js we received a more detailed warning message on build that may be helpful: