Module "util" has been externalized for browser compatibility. Cannot access "util.promisify" in client code
Asked Answered
T

3

6

I am trying to scrape LinkedIn profile using this library: https://www.npmjs.com/package/@n-h-n/linkedin-profile-scraper. This is my code:

<script>
import { LinkedInProfileScraper } from '@matidiaz/linkedin-profile-scraper';
    import { onMount } from 'svelte';
    import { session } from '$app/stores';

    onMount(async () => {
        const token = session?.provider_token;
    console.log(token);
        const scraper = new LinkedInProfileScraper({
            sessionCookieValue: token,
            keepAlive: false
        });

        // Prepare the scraper
        // Loading it in memory
        await scraper.setup();

        const result = await scraper.run('https://www.linkedin.com/in/jvandenaardweg/');

        console.log(result);
    });
</script>

I am using sveltekit to get the information, can someone point out how to solve this problem, I am not finding much information online.

Tarbes answered 12/8, 2022 at 14:7 Comment(0)
T
0
npm i util,

however this lib continues giving errors so I removed it.

Tarbes answered 12/8, 2022 at 18:51 Comment(0)
D
14

Hi what worked for me was to fix the vite.config.ts to add resolve.alias options like this:

resolve: {  
    alias: {
        process: "process/browser",
        stream: "stream-browserify",
        zlib: "browserify-zlib",    
        util: "util/",
        '@': path.resolve(__dirname, './src'),
    }
}

where we actually resolve the alias of util and add to it 'util/'

Diagnostician answered 14/8, 2022 at 7:39 Comment(1)
To be fair, this answer does not address the OP's question, but it helped me. To clarify, add to your vite.config.ts defineConfig({ resolve: { alias: { util: "util/" } } });.Parsley
T
0
npm i util,

however this lib continues giving errors so I removed it.

Tarbes answered 12/8, 2022 at 18:51 Comment(0)
U
0
https://www.npmjs.com/package/@browsery/util

npm i @browsery/util -s

Vite config alias add:

util: "@browsery/util"
Utopian answered 27/11, 2023 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.