jedisct1 / libsodium.js

libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Other
968 stars 138 forks source link

Vite build (with sveltekit) fails because of path resolution #300

Closed lmtr0 closed 2 years ago

lmtr0 commented 2 years ago

Hey there, good day! for some reason, when I try to build my frontend with libsodium, it fails while trying to use path. Is there any package that doesn't include require('path')

build log

lmtr0 commented 2 years ago

issue with node_modules/.vite, deleting it solves the problem

lmtr0 commented 2 years ago

Now that I got the same error with svetelkit cloudflare adapter, the solution is: in vite.config.js:

import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
    ssr: {
        noExternal: [
            'libsodium-wrappers'
        ],
    },
    plugins: [sveltekit()],
    resolve: {
        alias: {
            'path': 'path-browserify',
            'fs': 'path-browserify',
        }
    }
};

export default config;