Replies: 2 comments
-
You have to tell the bundler to exclude this dependency, in Next 15 it is done like: /** @type {import('next').NextConfig} */
const nextConfig = {
serverExternalPackages: ['soap'],
};
module.exports = nextConfig; Warning This is for Next.js version 15 - keep reading on for version 14.2.8 And then, you'd do: const soap = require('soap');
export function GET() {
console.log(typeof soap.createClientAsync);
return Response.json({});
} Now, you have v14.2.8, so I think you need, to use this other property (it has changed names in latest releases): Important I think this is the configuration you need in version 14.2.8, together with the /** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ['soap'],
},
};
module.exports = nextConfig; Let me know if it works! Here it is live, https://stackblitz.com/edit/nextjs-fe3abgs4?file=app%2Ffoo%2Froute.ts,next.config.js,package.json - just manually go to the |
Beta Was this translation helpful? Give feedback.
-
same logic for strong-soap
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Soap package is not working in nextjs 14 app router version 14.2.8
Getting this error
Cannot read properties of undefined (reading 'createClientAsync')
`app.post("/postcapability", async (req, res) => {
const url = "https://dhlindiaplugin.com/example.svc?wsdl";
const headers = {
"Content-Type": "text/xml; charset=utf-8",
SOAPAction: "http://tempuri.org/PostCapability",
};
const args = {
Address1: "TEST",
Address2: "TEST",
Address3: "TEST",
PostalCode: "10012",
City: "NEW YORK",
Division: "NY",
CountryCode: "US",
CountryName: "UNITED STATES OF AMERICA",
AuthToken: "YOUR_AUTH_TOKEN",
SessionID: "12345",
};
try {
const client = await soap.createClientAsync(url);
client.addSoapHeader(headers);
const [result] = await client.PostCapabilityAsync(args);
const xmlResponse = result.PostCapabilityResult;
const parsedResult = await parseStringPromise(xmlResponse, {
explicitArray: false,
});
res.json(parsedResult);
} catch (error) {
res
.status(500)
.json({ error: "Error calling SOAP method: " + error.message });
}
});`
The same code is working in nodejs
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions