【发布时间】:2019-07-16 19:43:56
【问题描述】:
我正在使用 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);
}
}
我希望程序包能够加载,这样我就可以根据提交的联系表单发送电子邮件。实际结果给我带来了上述错误。
【问题讨论】:
-
试试这个命令:
npm start -- --reset-cache -
尝试@fayeed 后我仍然收到错误
标签: react-native react-native-ios