AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS
http://aka.ms/aadv2
MIT License
3.61k stars 2.64k forks source link

Webpack 5 compatibility and crypto dependency #5598

Closed rsudworth closed 10 months ago

rsudworth commented 1 year ago

Core Library

MSAL Node (@azure/msal-node)

Core Library Version

1.14.6

Wrapper Library

Not Applicable

Wrapper Library Version

None

Public or Confidential Client?

Public

Description

I'm using msal to manage authentication for embedded PowerBI reports in an MS Dynamics ecommerce solution (https://github.com/microsoft/Msdyn365.Commerce.Online). A recent upgrade to the dynamics code included a requirement for webpack 5, which has led to the build now failing as follows:

"message": "Module not found: Error: Can't resolve 'crypto' in 'E:\\source\\repos\\xxx-xxx-xxx\\node_modules\\@azure\\msal-node\\dist'\n\nBREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.\nThis is no longer the case. Verify if you need this module and configure a polyfill for it.\n\nIf you want to include a polyfill, you need to:\n\t- add a fallback 'resolve.fallback: { \"crypto\": require.resolve(\"crypto-browserify\") }'\n\t- install 'crypto-browserify'\nIf you don't want to include a polyfill, you can use an empty module like this:\n\tresolve.fallback: { \"crypto\": false }"

As I understand it, webpack 5 stopped including some common Node libraries liike crypto and the recommended solution is to add a polyfill, as described by the error message. Unfortunately, the webpack build and config for the solution is wrapped in custom build scripts that aren't available to the developer. Is there any other work around available? Or perhaps an update is due soon that moves away from relying on the crypto library?

Thanks.

MSAL Configuration

No response

Relevant Code Snippets

No response

Identity Provider

Azure AD / MSA

Source

External (Customer)

jo-arroyo commented 1 year ago

@bgavrilMS for visibility

ghost commented 1 year ago

@rsudworth This issue has been automatically marked as stale because it is marked as requiring author feedback but has not had any activity for 5 days. If your issue has been resolved please let us know by closing the issue. If your issue has not been resolved please leave a comment to keep this open. It will be closed automatically in 7 days if it remains stale.

bgavrilMS commented 1 year ago

Possible duplicate: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/5602

DxDen1004 commented 1 year ago

I do not understand why this issue is marked as "completed". Completed what? Where is the answer to the author's question (and many more people's question)? Where is the fix?

Three years later and still, creating a React Solution in Visual Studio 2022 Enterprise edition (and not just running create-react-app from the cli), will present you with a project that won't even start as soon as you install @azure/msal-node because of this "Module not found" error (which appears to me as quite different from the No Matching Export issue). How are we supposed to use msal with node? Is msal-node deprecated? Why it is not working as expected when installed on a freshly created project?

` "message": "Module not found: Error: Can't resolve 'crypto' in 'E:\source\repos\project_folder\node_modules\@azure\msal-node\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:

If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "crypto": false }"`

If you try to follow the suggestion in the error message and edit the webpack config file to add the fallback, you will get tons and tons more "can't resolve" errors.

Should we just stop using this package?

crysiscore commented 11 months ago

im having the same issue @DxDen1004 . installing @azure/msal-node results in a compile error: BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:

If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "crypto": false }"`

If you try to follow the suggestion in the error message and edit the webpack config file to add the fallback, you will get tons and tons more "can't resolve" errors.

SaraRavasio commented 11 months ago

i'm having a similar experience!

i first get an error for http and https.

image

after they're added in the resolve.fallback, i get this new error

image