首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Haste模块映射中不存在haste模块'nodemailer‘

Haste模块映射中不存在haste模块'nodemailer‘
EN

Stack Overflow用户
提问于 2019-07-17 03:43:56
回答 1查看 89关注 0票数 0

我正在从beonews pro模板构建一个移动应用程序。我需要添加一些联系人表单的电子邮件功能。所以我自然而然地执行了npm install nodemailer,只看到了下面的错误。

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

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

代码语言:javascript
复制
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-*

执行完上述步骤后,我仍然收到相同的错误。

代码语言:javascript
复制
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);
  }
}

我期望的包加载,以便我可以发送一个电子邮件的基础上联系形式提交。实际结果给我带来了上述错误。

EN

回答 1

Stack Overflow用户

发布于 2019-07-17 21:37:05

在这种情况下,对我起作用的是确保我在遵循以下四个步骤后重新启动了计算机。我想可能和模拟器有关吧?但我不确定。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57064419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档