-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate Deprecated DNS Module Import #371
Conversation
This PR addresses a deprecated DNS module import, following Vite's documentation guidance. Vite discourages the use of Node.js modules in the browser due to potential bundle size increase. The import block has been removed, aligning the codebase with recommended practices for more efficient and browser-compatible builds. The adjustment reflects Vite's emphasis on minimizing the inclusion of Node.js-specific modules in client-side code. I would like to extend my sincere apologies for any inconvenience caused by the recent pull request. After careful reconsideration, I've recognized an error in my assessment, and the changes made in the previous pull request were not aligned with the best interests of the project. This new pull request aims to definitely remove the DNS module import, ensuring that the application's functionality is maintained as intended. I appreciate your understanding, and I apologize for any confusion caused.
👷 Deploy request for nuxt-strapi-module pending review.Visit the deploys page to approve it
|
Why would you remove this? I've just added this to fix the cookie being removed on localhost with Node 18 as you can read in the comment above this code. |
Hi @benjamincanac, thank you for your comment. I removed the code because Vite was still generating a warning despite the fix. The warning message indicates that the "dns" module has been externalized for browser compatibility. You can find more details about this warning here. |
Hi @benjamincanac export default defineNuxtPlugin({
name: 'dns_ipv4first',
parallel: true,
async setup (nuxtApp) {
// Fixes `ECONNREFUSED` on Node 18: https://github.com/node-fetch/node-fetch/issues/1624#issuecomment-1407717012
// Import dns only if running in a server environment during development
if (process.dev) {
try {
const dns = await import("dns");
await dns.setDefaultResultOrder("ipv4first");
} catch (error) {
console.error("Error importing dns module:", error);
}
}
}
}); And the issue is resolved. What do you think of my approach? |
It works for me! Do you feel like updating your PR with this? 😊 Why If you make this change I would create a plugins dir inside |
So we need an other PR to create a new file : "/runtime/plugins/dns.server.ts": export default defineNuxtPlugin({
name: 'dns_ipv4first',
parallel: true,
async setup (nuxtApp) {
// Fixes `ECONNREFUSED` on Node 18: https://github.com/node-fetch/node-fetch/issues/1624#issuecomment-1407717012
// Import dns only if running in a server environment during development
if (process.dev) {
try {
const dns = await import("dns");
await dns.setDefaultResultOrder("ipv4first");
} catch (error) {
console.error("Error importing dns module:", error);
}
}
}
}); |
I can push directly if you prefer, just let me know! |
Yes please |
Closing in favor of 13aa063 |
Thanks @ram-you! |
This PR addresses a deprecated DNS module import, following Vite's documentation guidance. Vite discourages the use of Node.js modules in the browser due to potential bundle size increase. The import block has been removed, aligning the codebase with recommended practices for more efficient and browser-compatible builds. The adjustment reflects Vite's emphasis on minimizing the inclusion of Node.js-specific modules in client-side code.
I would like to extend my sincere apologies for any inconvenience caused by the recent pull request https://github.com/nuxt-modules/strapi/pull/370.
After careful reconsideration, I've recognized an error in my assessment, and the changes made in the previous pull request were not aligned with the best interests of the project. This new pull request aims to definitely remove the DNS module import, ensuring that the application's functionality is maintained as intended. I appreciate your understanding, and I apologize for any confusion caused.
Types of changes
Description
Vite recommend avoiding Node.js modules for browser code to reduce the bundle size
Checklist: