Forum Discussion

AnthonyF's avatar
AnthonyF
Regular Visitor
1 year ago
Solved

Webpack 5 compatibility and crypto dependency when importing @azure/msal-node

Hello, I'm trying to build the node exemple provided in an existing Webpack5 config running on node 18. As soon as I import the class "ConfidentialClientApplication" from Azure/msal-node, I get the...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi, AnthonyF 

    Firstly, as Webpack 5 no longer includes polyfills for Node.js core modules by default, you will need to add them explicitly. You've already begun addressing the crypto module, but you'll also need to add polyfills for other modules.Below are screenshots from the relevant documentation:

    For further details, please refer to:

    Resolve | webpack

     

    Secondly, ensure that you have installed the necessary polyfill packages.

    Here are some reference examples:

    npm install --save-dev crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process
    

    How to polyfill node core modules in webpack 5

     

    Next, make sure your Webpack configuration is correctly set up to handle .mjs files:

    Loaders | webpack

     

    Finally, here are some related documents I found that I hope will be helpful to you:

    webpack 5 & next.js 10 - how to add resolve fallback to config - DEV Community

     next.config.js Options: webpack | Next.js

    Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
     

    Best Regards,

    Leroy Lu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.