NuxtJS:EmailJS找不到依赖项“ fs”

JavaScript Vue.js

Tom凯

2020-04-07

Goal️目标

emailjsNuxtJS应用程序中使用发送电子邮件


👾问题

最初,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)/
      })
    }
  }
}

投资价值

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"
},

第4132篇《NuxtJS:EmailJS找不到依赖项“ fs”》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
猴子 2020.04.07

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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android