Closed milahu closed 1 year ago
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.
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
}
Click the search input and be able to see the Algolia-integrated search box.
Nothing happens, instead, I see the following error log in the devtool console:
I did install your plugin in order to get it fixed, but no magic happens.
i moved to https://github.com/sodatea/vite-plugin-node-stdlib-browser
... just works
@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?
what's your use case for using the
node:
protocol if you plan to polyfill the imports anyway?
make node imports explicit
This has been fixed in v0.3.0
.
@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 thenode:
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
.
@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.
ideally
node:
protocol should workquickfix: remove the
node:
protocol from imports