繁体   English   中英

NuxtJS:EmailJS无法找到依赖'fs'

[英]NuxtJS: EmailJS Can't Find Dependency 'fs'

⚽️目标

NuxtJS应用程序中使用emailjs发送电子邮件。


👾问题

最初,尽管安装了fs但无法找到它们。

This dependency was not found: fs in ./node_modules/emailjs/smtp/message.js

根据这个类似的问题 ,应该通过将target: 'node'添加到webpack.config.js来解决问题。 我说注射到配置nuxt.config.js因为是Nuxt.js方式 (我认为),但会生成以下错误:

WebpackOptionsValidationError: Invalid configuration object.
Webpack has been initialised using a configuration object that
does not match the API schema.
  - configuration.module.rules[10] has an unknown property 'target'.
    These properties are valid: object { enforce?, exclude?, include?,
    issuer?, loader?, loaders?, oneOf?, options?, parser?, query?,
    resource?, resourceQuery?, compiler?, rules?, test?, use? }

这是否意味着它目前不可能? 😱


⌨️代码

nuxt.config.js

build: {
  /*
  ** Run ESLint on save
  */
  extend (config, { isDev, isClient }) {
    config.module.rules.push({target: 'node'}) // <-- Added this

    if (isDev && isClient) {
      config.module.rules.push({
        enforce: 'pre',
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        exclude: /(node_modules)/
      })
    }
  }
}

investment.vue

export default {
  asyncData ( context ) {
    let email = require('../node_modules/emailjs/email');

    console.log('process.server', process.server); // Evalutes to true
  }
};

的package.json

"dependencies": {
  "emailjs": "^2.2.0",
  "fs": "^0.0.1-security",
  "net": "^1.0.2",
  "nuxt": "^1.0.0",
  "tls": "^0.0.1"
},

Nuxt代码分为客户端和服务器部分。 您尝试在组件中使用库emailjs ,这是客户端部分。 它无法访问fs库(在Web中)。 您需要在服务器部分编写它(例如,在为您的页面提供服务的express服务器中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM