3

I am trying to use the npm-package soap in my SAPUI5 APP.

I am new to web development, so I tried to follow this tutorial:
https://github.com/SAP-samples/ui5-typescript-tutorial/tree/main/exercises/ex8

What I have tried:

  • Created an SAPUI5-project with yeoman-generator easy-ui5 ts-app
  • Installed soap as a development dependency
  • Tried to import the createClient method into a controller:
    import { createClient } from "soap"
  • Create a client:
    const SOAPClient:any = createClient("",function(){});
  • Run the app with npm start

But I get errors like this in chrome console:

GET http://</resources/http.js net::ERR_ABORTED 404 (Not Found) loadScript @ ui5loader.js:1351 2022-05-24 10:39:01.476100 failed to load JavaScript resource: http.js - sap.ui.ModuleSystem Log.js?eval:452

In the terminal I get messages like:

preferring built-in module http over local alternative at /home/user/projects/zvtle.om/node_modules/string_decoder/lib/http.js, pass preferBuiltins: false to disable this behavior or preferBuiltins: true to disable this warning

In Chrome under sources then resources I can see that the UI5 libraries are loaded, and a soap.js file that has been parsed and now uses sap.ui.definde. However, all of the packages that soap would require (such as http) are not loaded.

I have searched a long time and did not find where I could parse preferBuiltins: true as mentioned in the terminal output and I am not even sure if that would fix my problems.

Mike
  • 14,010
  • 29
  • 101
  • 161
NKN30
  • 33
  • 3
  • I'm not sure and I can't try, but since it seems to be a typescript import error, perhaps this is a flag that needs to be set in the compiler options of tsconfig.json. What are you trying to do with a separate soap client for dev puproses? – Jorg May 25 '22 at 02:48
  • @Jorg, I tried a buch of differend options in the compiler, without success. Currently I have it like this: `"compilerOptions": { "target": "es2015", "module": "es2015", "esModuleInterop": true, "allowSyntheticDefaultImports": true, "moduleResolution": "node", "allowJs": true, ... },` I'm trying to use the soap client for invoking multiple soap webservice operations. – NKN30 May 25 '22 at 09:58

1 Answers1

1

the npm package soap is for Node.js and does not work in a browser. The http package is a standard Node.js package.

I think the package easy-soap-request (https://www.npmjs.com/package/easy-soap-request) might fit your need. I have no experience with this package though, but the readme provides an example from the browser.

Allard
  • 186
  • 1
  • 8
  • Is there any way to use standard node packages in UI5 (typescript)? – NKN30 Sep 26 '22 at 11:08
  • 1
    Node packages cannot be used in a regular browser. You can use Node packages in an Electron app, but that requires installing an application on the client PC. Are you trying to integrate your UI5 application with an SAP system? Because if so, it is way easier to create OData Gateway services in the SAP system for your needs instead of using SOAP. UI5 supports OData Gateway services out of the box. – Allard Sep 26 '22 at 20:29