Skip to content
New issue

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

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

Already on GitHub? # to your account

[Issue] Cannot redefine property: crypto #10252

Closed
N-NeelPatel opened this issue Jun 26, 2023 · 32 comments
Closed

[Issue] Cannot redefine property: crypto #10252

N-NeelPatel opened this issue Jun 26, 2023 · 32 comments

Comments

@N-NeelPatel
Copy link

N-NeelPatel commented Jun 26, 2023

possible solution

#10252 (comment)

Describe the bug

When I create a new project in svelte using these commands:

npm create svelte@latest my-app
cd my-app
npm install
npm run dev -- --open

I get this issue
|
image

Reproduction

When I create a new project in svelte using these commands:

npm create svelte@latest my-app
cd my-app
npm install
npm run dev -- --open

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
    Memory: 829.25 MB / 7.36 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1848.0)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0
    @sveltejs/kit: ^1.20.4 => 1.20.5
    svelte: ^4.0.0 => 4.0.0
    vite: ^4.3.6 => 4.3.9

Severity

blocking all usage of SvelteKit

Additional Information

No response

@gtm-nayan
Copy link
Contributor

I cannot reproduce it with the default template with Node 16.15.0. We'll need a complete reproduction if you've made any modifications to the template.

@N-NeelPatel
Copy link
Author

N-NeelPatel commented Jun 26, 2023

@gtm-nayan - No, I didn't make any modification to the template

@N-NeelPatel
Copy link
Author

N-NeelPatel commented Jun 26, 2023

@gtm-nayan - these options I selected while setting up repo
image

@chrisflatley
Copy link

I also have this same error, but only after adding few dependencies to the template and on existing projects with templates.

When I remove the dependencies I've added, the error stays (even after delete package locks, node_modules and .sveltekit dir). Which makes no sense to me.

My stack is different pnpm (or npm), Node 18, MacOS, with Typescript.

I'm trying to figure which dependencies it is - perhaps multiple version sof sveltekit being pulled in.

@dagthomas
Copy link

I suddenly got this error too - was working on friday, not working today. Also persists through deletion of package-lock and node_moduls

@AntonPavlenkov
Copy link

AntonPavlenkov commented Jun 26, 2023

Have same issue with node v16.19.0 but Fixed this by updating to lates node v20.3.1.

@N-NeelPatel
Copy link
Author

@AntonPavlenkov - Thank you very much. The latest node v20.3.1 resolved the issue for me.

@dikshantrajput
Copy link

@gtm-nayan Is there any update on this one? I can not rely on updating version to 20.3.1 Other things might break.

@AntonPavlenkov
Copy link

You update only your local machine for development with node 20. Build with version 16 is fine and deploying to docker with node 16 is also working fine.

Although you are correct that it needs to be resolved properly.

@drewbitt
Copy link

Also broken on node 18.15

@gtm-nayan
Copy link
Contributor

Unfortunately I cannot reproduce the problem myself and I can't really investigate the problem with being able to recreate it. If you can't change the major version see if an upgrade or downgrade within the same major helps.

@Conduitry
Copy link
Member

I can't reproduce this either. I've installed Node 16.15.0 on a fresh Windows 11 sandbox, and I'm not getting this error with the default template.

@DoisKoh
Copy link

DoisKoh commented Jun 27, 2023

Broken on NodeJS v18.14.0 | Windows 11 for me.

Updated to NodeJS v20.3.1 | Windows 11 and the error went away.

@Conduitry
Copy link
Member

I'm unable to reproduce this on Node 18.14.0 on Windows 11 either.

@dikshantrajput
Copy link

@DoisKoh @dagthomas @AntonPavlenkov Have you freshly installed the node on your system or it was previously installed?

@dagthomas
Copy link

@DoisKoh @dagthomas @AntonPavlenkov Have you freshly installed the node on your system or it was previously installed?

I had an ongoing project, everything was previously installed. Happened from Friday to Monday where it didn't work anymore, unless I installed node 20

@AntonPavlenkov
Copy link

@DoisKoh @dagthomas @AntonPavlenkov Have you freshly installed the node on your system or it was previously installed?

It was installed before and was working fine until Monday. Although I use nvm on Mac m1 for that matter.

@vnphanquang
Copy link
Contributor

vnphanquang commented Jun 27, 2023

This happened to me today as well. Deleting node_modules and reinstalling resolved the error.

This is on Mac 13.0.1 (22A400), Node 18.16.0, pnpm 8.4.0. The steps taken were hard track. I can provide package.json and more env details if someone needs that.


UPDATE: happens again after machine reboot.

@chrisflatley
Copy link

chrisflatley commented Jun 27, 2023

This is hard to reproduce I’ve failed even though I’ve hit it on several projects (starting from clean and from existing).

Whilst it’s not addressing the issue should the install polyfill check if crypto etc is already defined?

or try-catch and log a warning?

It currently just overwrites everything on globalThis as far as I can see.

@Holf
Copy link

Holf commented Jun 27, 2023

Have had exactly the same experience on Windows 11, WSL2 (Ubuntu 20.04.6).

  • Node v18.14.2
  • SvelteKit 1.20.4

Working fine last night (approx 21:00 BST).
Fails this morning (09:00 BST).

Only obvious moving pieces on my system:

  • A major Windows 11 update was attempted last night, but failed.
  • There was an anti-virus definitions update.

Given this effects MacOS users, too, I can't think these are relevant.


As with others, upgrading Node (to v20.3.1) fixes the issue.

@nostrorom
Copy link

nostrorom commented Jun 27, 2023

I and other collaborators are having the same issue.

As with other posts mentioned above, it happened overnight with no discernable change.
Some people on the same OS/stack are not having it; some fixed it by doing a lot of stuff so unsure what did work.

It's a weird case to reproduce or not - hard to pinpoint how and why it happens, or how and why it doesn't happen.

   turbo: 1.10.6,
   @sveltejs/kit: ^1.15.8,
   vite:  ^4.2.1,
   
   node 18.16.1
   Ubuntu 22.04.2 LTS

Switching to node 20.3.1 solved the issue - though I can't go in production with it, we're still on 18.x

@jnath
Copy link

jnath commented Jun 27, 2023

this post related the same issue

https://stackoverflow.com/questions/76557205/why-wont-vite-server-start

@sudo-mehedi
Copy link

Same issue with Node.js v18.13.0.

Worked last night!

@SaidBahaDev
Copy link

same error on node v18.16.1

danielres added a commit to danielres/pixel-avatar-editor that referenced this issue Jun 28, 2023
@dummdidumm
Copy link
Member

dummdidumm commented Jun 28, 2023

To everyone affected by this: Do you have the "Console Ninja" extension installed by any chance? If so, this might be the culprit, as hinted by this related issue. If so, try updating the extension to the latest version, then delete your node modules folder in the offending project and reinstall the packages, which hopefully fixes this.

@AntonPavlenkov
Copy link

Actually I do have it "Console Ninja" installed. So after uninstalling it and trying again it did not work. Also from trying to start it from pure terminal without IDE it also does not work.

@gtm-nayan
Copy link
Contributor

gtm-nayan commented Jun 28, 2023

@AntonPavlenkov can you try again after removing the node_modules and doing a force install?

@AntonPavlenkov
Copy link

AntonPavlenkov commented Jun 28, 2023

@gtm-nayan yes! So after uninstalling Console Ninja and removing node_module and package.lock and .svelte-kit and running fresh install. The error goes away. But it is enough to just install Console Ninja again and error comes back!

So the question is... where we should expect fix to come from svelte-kit or from console-ninja?

@Holf
Copy link

Holf commented Jun 28, 2023

I am using Console Ninja, yes.

I have upgraded it to v0.0.167, released today.

I am now able to start Vite Server just fine on Node v18.14.2 again.

Thank you for identifying this resolution so quickly.

@nostrorom
Copy link

nostrorom commented Jun 29, 2023

Same here, upgrading to the latest Console Ninja >v0.0.167 has solved my issue (without having to remove node_modules, package-lock etc.) 👍

@N-NeelPatel that should solve the issue

@chanmathew
Copy link

To everyone affected by this: Do you have the "Console Ninja" extension installed by any chance? If so, this might be the culprit, as hinted by this related issue. If so, try updating the extension to the latest version, then delete your node modules folder in the offending project and reinstall the packages, which hopefully fixes this.

Wow great find! Just updated Console Ninja to v0.0.170 and removed my node_modules and did a fresh install. Seems to be resolved now, thank you!

@elliott-with-the-longest-name-on-github
Copy link
Contributor

Closing this since the issue was external and is now fixed. For future googlers -- upgrade Console Ninja, remove node_modules, and reinstall.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests