Sendgrid Node.js库不能与React一起工作

Sendgrid Node.js library doesn't work with React

本文关键字:React 一起 工作 不能 Node js Sendgrid      更新时间:2023-09-26

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

我一直得到这个错误,我认为这是一个Webpack问题。在这里输入图像描述我还将发布几行代码。

你知道我该怎么做吗?

//Webpack。配置文件

 "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(),
    ]
};

我找到了这个问题的解决方案

这不是一个问题,你的webpack配置只需要一个json加载器,见这个问题:

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

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

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