Skip to main content

解决nuxt依赖Node原生模块导致构建失败问题

· One min read
Alan

修改 nuxt.config.js 中的 webpack 配置:

nuxt.config.js
export default {
// ... 其他配置
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
extend(config) {
// #region 解决日志模块fs依赖问题
/**
* ref: https://stackoverflow.com/questions/40959835/webpack-express-cannot-resolve-module-fs-request-dependency-is-expression#40998972
* ref: https://blog.csdn.net/guyue_01/article/details/125298203
* ref: https://maikelveen.com/blog/how-to-solve-module-not-found-cant-resolve-fs-in-nextjs
*/
if (!config.node) {
config.node = {};
}
config.node.fs = "empty";
// #endregion
}
}
}