Giter VIP home page Giter VIP logo

Comments (7)

quocvo1707 avatar quocvo1707 commented on May 25, 2024 1

I also got into the same problem as you did. My site uses not Vite but rather Astro; however, I think they're not different from the rest since Astro is powered by Vite underneath.

Reproduction

import { readdirSync } from "node:fs"

const format = (text: string): string => {
    const capitalizedString = text.charAt(0).toUpperCase() + text.slice(1)
    const finalString = capitalizedString.replace(/\-/gm, ' ')

    return finalString
}

export const getFilesInDirectory = (path: string): { text: string, link: string }[] => {
    const dir = path.split('/').pop() as string
    const filesInDir =
        readdirSync(path, { withFileTypes: true })
            .filter((item) => !item.isDirectory())
            .map(({ name }) => name.split('.')[0])
    const files = filesInDir.map(file => {
        return {
            text: format(file),
            link: `${dir}/${file}`,
        }
    })

    return files
}

Expected behavior

Click the search input and be able to see the Algolia-integrated search box.

Actual behavior

Nothing happens, instead, I see the following error log in the devtool console:

Screenshot 2022-09-25 174052

I did install your plugin in order to get it fixed, but no magic happens.

from vite-plugin-node-polyfills.

milahu avatar milahu commented on May 25, 2024

i moved to https://github.com/sodatea/vite-plugin-node-stdlib-browser

... just works

from vite-plugin-node-polyfills.

davidmyersdev avatar davidmyersdev commented on May 25, 2024

@quoc1707 my other plugin does not take node: protocol imports into account, but I'll likely want to update it to allow those to be externalized. As for this package, I'm going to guess the underlying library I'm using doesn't recognize the protocol imports either. If you don't mind me asking, what's your use case for using the node: protocol if you plan to polyfill the imports anyway?

from vite-plugin-node-polyfills.

milahu avatar milahu commented on May 25, 2024

what's your use case for using the node: protocol if you plan to polyfill the imports anyway?

make node imports explicit

from vite-plugin-node-polyfills.

davidmyersdev avatar davidmyersdev commented on May 25, 2024

This has been fixed in v0.3.0.

from vite-plugin-node-polyfills.

quocvo1707 avatar quocvo1707 commented on May 25, 2024

@quoc1707 my other plugin does not take node: protocol imports into account, but I'll likely want to update it to allow those to be externalized. As for this package, I'm going to guess the underlying library I'm using doesn't recognize the protocol imports either. If you don't mind me asking, what's your use case for using the node: protocol if you plan to polyfill the imports anyway?

I just want to clarify that the import is a Node.js built-in module, since there're many alternative packages for these nowadays, like fs-extra or pathe.

from vite-plugin-node-polyfills.

davidmyersdev avatar davidmyersdev commented on May 25, 2024

@quoc1707 I figured that's what you meant. It definitely makes sense that you'd want to be able to polyfill the builtins, and I was able to get it working with node-stdlib-browser. I looked into sodatea/vite-plugin-node-stdlib-browser as suggested by @milahu, but it didn't correctly handle calls to process in the production build (dev server worked fine though). I think the newest version is a bit more robust, and I plan to introduce some configuration to allow you to toggle the node: behavior. I can imagine a scenario where you might want to polyfill regular imports (e.g. 'fs') and leave protocol imports alone (e.g. node:fs), and having a bit more control over the polyfills, in general, is something I will likely need in the near future.

from vite-plugin-node-polyfills.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.