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 669 forks source link

Latest version creates runtime error when bundled: `Class constructor BaseService cannot be invoked without 'new'` #1119

Closed bwilloughby1 closed 2 years ago

bwilloughby1 commented 2 years ago

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:
image

SDK Version ibm-watson 6.2.1

Additional 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:

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
apaparazzi0329 commented 2 years ago

@bwilloughby1 has this issue been resolved using the latest version of the node-sdk-core?

bwilloughby1 commented 2 years ago

This issue is now resolved with the latest version. Thank you!