var transporter导致webpack错误,我不知道为什么。我有nodemailer的最新版本

时间:2017-09-17 20:49:08

标签: reactjs webpack nodemailer

import React, { Component } from 'react'
import { render } from 'react-dom'
import { BrowserRouter, Route, Link, history } from 'react-router-dom'
import Footer from "./Footer"
import Menu from './Menu'
import {Helmet} from 'react-helmet'
import Scroll from 'react-scroll'
import Validation from 'react-validation'
import classNames from 'classnames'
import PropTypes from 'prop-types'
import { ajax } from 'jquery'
import nodemailer from 'nodemailer'
import smtpTransport from 'nodemailer-smtp-transport'


export default class Form extends Component {

  var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: 'gmail.user@gmail.com',
        pass: 'userpass'
    }
});


constructor(props) {
    super(props);
    this.state = {
      Form: {
        Name: "",
        Email: "",
        Website: "",
        Subject: "",
        Message: ""
      }
    }
    this.onFormChange = this.onFormChange.bind(this)
  }

  onFormChange(e) {
    var formName = this._name.value
    var formEmail = this._email.value
    var formWebsite = this._website.value
    var formSubject = this._subject.value
    var formMessage = this._message.value
    console.log(formEmail);
    this.setState({
      Form: {
        Name: formName,
        Email: formEmail,
        Website: formWebsite,
        Subject: formSubject,
        Message: formMessage
      }
    })
  }


  onFormSubmit(e){
   e.preventDefault();
  }

  render() {
    const formInputs = this.state.Form

    return(
      <section>
        <Validation.components.Form
          method="post"
          onChange={this.onFormChange}>
          <input
          ref={input => this._name = input}
            name="Name"
            type="text"
            placeholder="NAME" />
          <input
            ref={input => this._email = input}
            name="Email"
            type="text"
            placeholder="EMAIL" />
          <input
            ref={input => this._website = input}
            name="Website"
            type="text"
            placeholder="WEBSITE" />
          <input
            ref={input => this._subject = input}
            name="Website"
            type="text"
            placeholder="SUBJECT" />
          <textarea
            ref={input => this._message = input}
            name="Message"
            type="text"
            placeholder="MESSAGE" />
          <input onSubmit={this.onFormSubmit.bind(this)} type="submit"/>
        </Validation.components.Form>
        <p>{this.state.Name}</p>
      </section>
    )
  }
}

这是我的package.json

"nodemailer": "^4.1.0",
"nodemailer-smtp-transport": "^2.7.4",

这是我正在获取的webpack错误。

ERROR in ./js/Form.js
Module build failed: SyntaxError: Unexpected token (26:6)

  24 | export default class Form extends Component {
  25 |
> 26 |   var transporter = nodemailer.createTransport({
     |       ^
  27 |     service: 'Gmail',
  28 |     auth: {
  29 |         user: 'gmail.user@gmail.com',

我不明白为什么这个声明的变量会导致这个错误。我按照了nodemailer docs看了看,但似乎无法找到发生这种情况的原因。一直坚持这个问题一周。我需要帮助。谢谢

0 个答案:

没有答案