【问题标题】:Sendgrid Node.js library doesn't work with ReactSendgrid Node.js 库不适用于 React
【发布时间】:2016-09-15 23:02:42
【问题描述】:

我需要帮助。我正在尝试使用 node.js 来处理在我的网站上发送电子邮件。我希望我的电子邮件表单继续并在提交时发送电子邮件,而不是使用基本的“mailto”操作。我将 Sendgrid 作为我的电子邮件服务来处理 API 和其他服务器端任务。

我不断收到此错误,我认为这是 Webpack 问题。 enter image description here 我还将发布几行代码。

你对我能做什么有什么想法吗?

//Webpack.config 文件

 "use strict";
var webpack = require('webpack');
var loaders = require('./webpack.loaders');
var HtmlWebpackPlugin = require('html-webpack-plugin');

const HOST = process.env.HOST || "127.0.0.1";
const PORT = process.env.PORT || "8888";

// global css
loaders.push({
    test: /[\/\\](node_modules|global)[\/\\].*\.css$/,
    loaders: [
        'css-loader!autoprefixer-loader?browsers=last 2 versions',
        'style-loader!css-loader!autoprefixer-loader',
        'style?sourceMap',
        'css'
    ]
});
//local sass modules
loaders.push({
    test: /[\/\\]src[\/\\].*\.sass/,
    loaders: [
        'style?sourceMap',
        'css-loader!autoprefixer-loader?browsers=last 2 versions',
        'style-loader!css-loader!autoprefixer-loader',
        'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
        'sass'
    ]
});
//local css modules
loaders.push({
    test: /[\/\\]src[\/\\].*\.css/,
    loaders: [
        'style?sourceMap',
        'css-loader!autoprefixer-loader?browsers=last 2 versions',
        'style-loader!css-loader!autoprefixer-loader',
        'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
    ]
});

module.exports = {
    entry: [
        `webpack-dev-server/client?http://${HOST}:${PORT}`,
        `webpack/hot/only-dev-server`,
        `./src/index.jsx` // Your appʼs entry point
    ],
    devtool: process.env.WEBPACK_DEVTOOL || 'cheap-module-source-map',
    output: {
        path:__dirname,
        filename: './src/bundle.js'
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    module: {
        loaders
    },
    devServer: {
        // do not print bundle build stats
        noInfo: true,
        // enable HMR
        hot: true,
        // embed the webpack-dev-server runtime into the bundle
        inline: true,
        // serve index.html in place of 404 responses to allow HTML5 history
        historyApiFallback: true,
        port: PORT,
        host: HOST
    },
    plugins: [
        new webpack.NoErrorsPlugin(),
        new webpack.HotModuleReplacementPlugin(),
    ]
};

【问题讨论】:

  • 在项目目录的控制台中你可以试试npm install --save-dev bluebird再试一次吗?
  • 我这样做了,但仍然出现第二个错误。该模块无法解析。
  • 看起来它是一个未解决的问题github.com/sendgrid/sendgrid-nodejs/issues/289
  • 好吧,我想我得另找办法了。我等不及要解决这个问题了。不过,感谢您的帮助。

标签: javascript node.js reactjs webpack sendgrid


【解决方案1】:

我确实找到了解决办法

这不是这个 repos 端的问题,你的 webpack 配置只需要一个 json 加载器,请参阅这个问题:

https://github.com/webpack/webpack/issues/303

我决定自己将 { test: /\.json$/, loader: 'json'} 添加到我的 webpackloaders

你可能还需要npm install json-loader --module-bind json

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2019-11-19
    • 2015-07-02
    • 2022-07-04
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    相关资源
    最近更新 更多