0

I get an error when I start the dev server


    error when starting dev server:
    TypeError: Cannot redefine property: crypto
        at Function.defineProperty (<anonymous>)
        at installPolyfills (file:///home/apache/svelte-dnd/node_modules/@sveltejs/kit/src/exports/node/polyfills.js:35:10)
        at dev (file:///home/apache/svelte-dnd/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:29:3)
        at configureServer (file:///home/apache/svelte-dnd/node_modules/@sveltejs/kit/src/exports/vite/index.js:605:17)
        at _createServer (file:///home/apache/svelte-dnd/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:63461:30)
        at async CAC.<anonymous> (file:///home/apache/svelte-dnd/node_modules/vite/dist/node/cli.js:733:24)

I was trying to add vite-plugin-node-polyfills to vite.config.js

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { nodePolyfills } from "vite-plugin-node-polyfills";

export default defineConfig({
    plugins: [
        sveltekit(),
        nodePolyfills({
            // Whether to polyfill `node:` protocol imports.
            protocolImports: true,
        }),
    ]
});```
Player
  • 1
  • 2

4 Answers4

1

EDIT: it was due to a conflict with a version of the Console Ninja extension. Upgrade to higher than v0.0.167 to solve.

https://github.com/sveltejs/kit/issues/10252#issuecomment-1612590791


Original post for the record:

Related issue in SvelteKit repo:

https://github.com/sveltejs/kit/issues/10252

TLDR: so far, for lack of better fix, switching to node 20 works

nostro
  • 71
  • 1
  • 3
1

Issue is related to the sveltekit. At the time of writing this, there is not solid fix for this issue. However, upgrading node version to v20.3.1 resolved the issue for many including myself.

What you can do is update only your local machine for development with node 20. Build with version 16 works fine and deploying to docker with node 16 also works fine.

(ref: https://github.com/sveltejs/kit/issues/10252)

Neel Patel
  • 11
  • 3
0

Not an answer I and some other collaborators are having a similar issue

TypeError: Cannot redefine property: crypto
    at Function.defineProperty (<anonymous>)
    at installPolyfills (file:///home/<pathToMyRepo>/node_modules/@sveltejs/kit/src/exports/node/polyfills.js:27:10)
    at dev (file:///home/<pathToMyRepo>/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:29:3)
    at configureServer (file:///home/<pathToMyRepo>/node_modules/@sveltejs/kit/src/exports/vite/index.js:600:17)
    at _createServer (file:///home/<pathToMyRepo>/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:63461:30)
    at async CAC.<anonymous> (file:///home/<pathToMyRepo>/node_modules/vite/dist/node/cli.js:733:24)
npm ERR! Lifecycle script `dev` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: @player/web@0.4.2 
npm ERR!   at location: /home/<pathToMyRepo>/apps/web 
ERROR: command finished with error: command (/home/<pathToMyRepo>/apps/web) npm run dev exited (1)

In a turbo/sveltekit/vite project

nostro
  • 71
  • 1
  • 3
0

For many on the Github issue, the issue was caused by having Console Ninja - upgrading to the latest version has solved the problem so far for those who have tried.

nostro
  • 71
  • 1
  • 3