Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to vite 3.1.4 - Module path has been externalized for browser in Chrome #10302

Closed
7 tasks done
rezelute opened this issue Sep 30, 2022 · 5 comments
Closed
7 tasks done

Comments

@rezelute
Copy link

Describe the bug

In a project I am currently using vite 2.9.15 and everything is working fine. When i upgraded to vite 3.1.4, I now get the following warning in Chrome:
browser-external:crypto:9 Module "crypto" has been externalized for browser compatibility. Cannot access "crypto.randomBytes" in client code.
image
It seems to be coming from importing bcrypt in a file but why is it throwing this warning after upgrading to the new vite version.

I have double checked this to make sure its the vite version causing issues by creating a new branch.

Any advice for what you think might be happening is appreciated!

Reproduction

Install the latest version of vite and import bcrypt

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 13.44 GB / 31.92 GB
  Binaries:
    Node: 14.20.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.5.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (105.0.1343.50)    
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-vue: ^2.3.4 => 2.3.4
    vite: ^3.1.4 => 3.1.4

Used Package Manager

npm

Logs

No response

Validations

@rezelute rezelute changed the title Module path has been externalized for browser in Chrome Upgrading to vite 3.1.4 - Module path has been externalized for browser in Chrome Sep 30, 2022
@github-actions
Copy link

github-actions bot commented Oct 1, 2022

Hello @rezelute. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@rezelute
Copy link
Author

rezelute commented Oct 1, 2022

Thanks for the reply.
Let me know if you have any trouble accessing this: https://stackblitz.com/edit/vitejs-vite-efwknr
But essentially if you just import bcrypt from "bcryptjs"; you will immediately see the warning, you dont even have to start using bcrypt in the project.
image

This error doesnt seem to happen with version 2 of vite for some reason.

@sapphi-red
Copy link
Member

But essentially if you just import bcrypt from "bcryptjs";

Because you were saying "bcrypt", I thought it was bcrypt package and a different behavior happened when I tried that. Now I understand you were intending bcryptjs package.

BTW the warning is happening because bcryptjs is accessing crypto here.
https://github.com/dcodeIO/bcrypt.js/blob/7e2e93af99df2952253f9cf32db29aefa8f272f7/src/bcrypt.js#L23-L26
The reason why this warning exists is explained at #9837.

@rezelute
Copy link
Author

rezelute commented Oct 1, 2022

Ah sorry about the confusion about bcrypt vs bcryptjs 😬.
Thank you for that explanation, do you have a recommendation as to what I could to to resolve the warning? Would you recommend a different node package instead which doesnt "try import and test if exist" ?

@sapphi-red
Copy link
Member

Yes, I would recommend that.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants