急速模块映射中不存在急速模块“ nodemailer”

时间:2019-07-16 19:43:56

标签: react-native react-native-ios

我正在使用beonews pro模板构建移动应用程序。我需要为联系表单添加一些电子邮件功能。因此,我自然npm install nodemailer只是为了看到以下错误。

Haste module 'nodemailer' does not exist in haste module map

它列出了要遵循的四个步骤

1.watchman watch-del-all
2.rm -rf node_module && yarn
3.rm -rf /tmp/metro-bundler-cache-*
4.rm -rf /tmp/haste-map-react-native-packager-*

按照上述步骤操作后,我仍然收到相同的错误。


import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { View, Text, ScrollView, TextInput, Button, Image, Animated } from 'react-native'
import wp from '@services/WPAPI'
import WebView from '@components/WebView/WebView'
import AnimatedButton from '@components/AnimatedButton/index'
import { Toolbar } from '@components'
import styles from './styles'


import nodemailer from 'nodemailer';


export default class CustomPage extends PureComponent {
  static propTypes = {
    id: PropTypes.any,
  }

  constructor(props) {
    super(props)
    this.state = {
      newsletterFName: '',
      newsletterLName: '',
      newsletterEmail: '',
      contactFName: '',
      contactLName: '',
      contactEmail: '',
      contactMessage: '',
      loading: false,
      success: false
    }
  }
  onSubmitNewsletter() {
    console.log('the form has been submitted');
    this.setState({
      loading: true
    })
    fetch('https://us18.api.mailchimp.com/3.0/lists/dad57ba7fe/members', {
      method: 'POST', // *GET, POST, PUT, DELETE, etc.
      mode: 'cors', // no-cors, cors, *same-origin
      cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
      credentials: 'same-origin', // include, *same-origin, omit
      headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
          // 'Content-Type': 'application/x-www-form-urlencoded',
      },
      redirect: 'follow', // manual, *follow, error
      referrer: 'no-referrer', // no-referrer, *client
      body: JSON.stringify({
        "email_address": this.state.newsletterEmail,
        "status": "subscribed",
        "merge_fields": {
          "FNAME": this.state.newsletterFName,
          "LNAME": this.state.newsletterLName
        }
      }), // body data type must match "Content-Type" header
    })
    .then(response => {
      console.log('response before timeout', response);
      setTimeout(() => {
        console.log('inside timout')
        if(response.status !== 200) {
          this.setState({
            loading: false,
          })
        } else {
          this.setState({
            loading: false,
            newsletterEmail: '',
            newsletterFName: '',
            newsletterLName: '',
            success: true
          })
        }
      }, 2000);
    });
  }
  onSubmitContactForm() {
    console.log('contact form submitted');
    let email = this.state.contactEmail;
    let first = this.state.contactFName;
    let last = this.state.contactLName;
    let msg = this.state.contactMessage;

    // async..await is not allowed in global scope, must use a wrapper
    async function main(){


      // create reusable transporter object using the default SMTP transport
      let transporter = nodemailer.createTransport({
        host: "smtp.office365.com",
        port: 587,
        secure: false, // true for 465, false for other ports
        auth: {
          user: 'xxx', // generated ethereal user
          pass: 'xxx' // generated ethereal password
        }
      });

      // send mail with defined transport object
      let info = await transporter.sendMail({
        from: '"Fred foos" <foo@example.com>', // sender address
        to: this.state.contactEmail, // list of receivers
        subject: 'News.Law Mobile Contact Form', // Subject line
        text: this.state.contactMessage, // plain text body
        html: this.state.contactMessage // html body
      });

      console.log("Message sent: %s", info.messageId);
      // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

      // Preview only available when sending through an Ethereal account
      console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
      // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
    }

    main().catch(console.error);
  }
}

我希望该软件包能够加载,因此我可以根据提交的联系表单发送电子邮件。实际结果使我遇到了上述错误。

1 个答案:

答案 0 :(得分:0)

在这种情况下,对我有用的是确保按照以下四个步骤重新启动计算机。我认为这可能与模拟器有关?但是不确定。