Comments (7)
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:
I did install your plugin in order to get it fixed, but no magic happens.
from vite-plugin-node-polyfills.
i moved to https://github.com/sodatea/vite-plugin-node-stdlib-browser
... just works
from vite-plugin-node-polyfills.
@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.
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.
This has been fixed in v0.3.0
.
from vite-plugin-node-polyfills.
@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
.
from vite-plugin-node-polyfills.
@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)
- Missing "./shims/global" specifier HOT 4
- TypeError: net.createConnection is not a function HOT 7
- When vite define contains process.env: xx, process polyfill will fail HOT 1
- Migrate to `unenv`
- Release `v1.0.0`
- Cannot find module 'vite-plugin-node-polyfills/shims/buffer' HOT 9
- Missing kMaxLength and SlowBuffer exposure HOT 1
- toString error with zlib starting with 0.18.0 HOT 2
- Failed to resolve module specifier "vite-plugin-node-polyfills/shims/global". Relative references must start with either "/", "./", or "../". HOT 3
- Failed to resolve import "vite-plugin-node-polyfills/shims/buffer" HOT 6
- Error when having type: module in package.json HOT 1
- `process` is not polyfilled if `viteConfig.define` is used to define, for example, a static environment variable in the form of `process.env.var_name` HOT 2
- Cannot access "fs/promises.readFile" in client code.
- bug: config `include: [],` treated as `no option is passed`
- Globals are always defined HOT 1
- Bug: conflict with another middleware plugin HOT 3
- Bug: PassThrough is not exported by "__vite-browser-external" during build
- Bug: exports is not defined HOT 2
- Bug: importing 'crypto' polyfill leads to error `exports is not defined` with yarn build && yarn preview in nuxt HOT 2
- Bug: `node:assert/strict` is not polyfilled
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite-plugin-node-polyfills.