Sendgrid-nodejs: 在Nuxt中使用sendgrid的问题

创建于 2017-08-29  ·  29评论  ·  资料来源: sendgrid/sendgrid-nodejs

在模块中需要sendgrid之后,我开始具有以下模块的未解决依赖性:fs,net,tls。 我现在正在使用最新的sendgrid-nodejs v6.0.0。
由于Nuxt是服务器端,因此我假设Nuxt不支持这些模块。 在Nuxt上使用sendgrid的示例吗?

help wanted question

最有用的评论

最终设法使其工作。 不确定之前是什么问题。 无论如何,“ nuxt.config.js”的摘录在哪里起作用,

  build: {
    extend (config) {
      config.node = {
        console: true,
        fs: 'empty',
        net:'empty',
        tls:'empty',
      }
    },
   ...

所有29条评论

你好@froquette

您能提供错误的日志文件吗? 谢谢!

最诚挚的问候,

埃尔默

声明sendgrid时:var helper = require('sendgrid')。mail

[email protected]开发人员C:\ nodejs \ jpServer \ jps01
纽克斯

错误编译失败,出现3个错误21:49:13

找不到此依赖项:

  • ./node_modules/mime/mime.js、./node_modules/sendgrid/lib/helpers/inbound/parse.js和另外1个文件中的fs

要安装它,您可以运行:npm install --save fs

@froquette

它看起来像你没有最新的软件包,可以请你试试这个

嗨,托马斯,
已经尝试使用此版本(v6.0.0)并获得了无法解析的依赖关系fo:fs,
TLS,净额。 我想Nuxt不支持这些模块。

2017年8月29日,星期二,晚上10:45,埃尔默·托马斯[email protected]
写道:

@froquette https://github.com/froquette

好像您没有最新的软件包,请您试试看
https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail#install-package


您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看
https://github.com/sendgrid/sendgrid-nodejs/issues/432#issuecomment-325813542
或使线程静音
https://github.com/notifications/unsubscribe-auth/AGHRvDF7oB8-4q33M90EeDRStG1uqUwPks5sdIZbgaJpZM4PGf2j

-
Cumprimentos,
菲利普·罗奎特

@froquette

您能否提供尝试安装v6时遇到的错误(来自日志)?

您尝试过npm install --save fs吗?

嗨,托马斯,
谢谢您的支持!!

由于v6.0.0显示未解决,因此我已还原到以前的版本
来自fs,tls和net的依赖项。 如果确实需要,我可以重新安装它并
向您发送显示这些问题的编译日志。

我试图安装“ fs”,但它会导致其他问题。 由于Nuxt是SSR
(服务器端渲染)我想像“ fs”这样的客户端模块不是
支持的。

2017年8月29日,星期二,晚上10:56,Elmer Thomas [email protected]
写道:

@froquette https://github.com/froquette

您能否提供您在日志中遇到的错误(来自日志)
您尝试安装v6?

您是否尝试过npm install --save fs?


您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看
https://github.com/sendgrid/sendgrid-nodejs/issues/432#issuecomment-325816203
或使线程静音
https://github.com/notifications/unsubscribe-auth/AGHRvNmrCg3uroNcipz4wH4UXevb7oYkks5sdIj7gaJpZM4PGf2j

-
Cumprimentos,
菲利普·罗奎特

你好@froquette

感谢更新! 日志将帮助我们确定是否有好的解决方法。 如果您有时间,很高兴见到他们。

最诚挚的问候,

埃尔默

这是具有package.json依赖项的日志:“ @ sendgrid / mail”:“ ^ 6.1.1”

[email protected]开发人员C:\ nodejs \ jpServer \ jps01
纽克斯

错误编译失败,出现6个错误17:57:10

找不到这些依赖项:

  • ./node_modules/request/lib/har.js中的fs
  • ./node_modules/forever-agent/index.js、./node_modules/tough-cookie/lib/cookie.js和另外1个网络
  • ./node_modules/forever-agent/index.js、./node_modules/tunnel-agent/index.js中的tls

要安装它们,您可以运行:npm install --save fs net tls

@froquette

这似乎有关: https :

尝试过,但仍然存在相同的问题。

2017年8月31日星期四,下午6:28,Elmer Thomas通知@ github.com
写道:

@froquette https://github.com/froquette

似乎相关:request / request#1529
https://github.com/request/request/issues/1529


您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看
https://github.com/sendgrid/sendgrid-nodejs/issues/432#issuecomment-326366422
或使线程静音
https://github.com/notifications/unsubscribe-auth/AGHRvBltsGrWEt3JkddfT49NPyyrKkxWks5sdu07gaJpZM4PGf2j

-
Cumprimentos,
菲利普·罗奎特

@froquette

您尝试了哪种解决方案?错误是什么?

最终设法使其工作。 不确定之前是什么问题。 无论如何,“ nuxt.config.js”的摘录在哪里起作用,

  build: {
    extend (config) {
      config.node = {
        console: true,
        fs: 'empty',
        net:'empty',
        tls:'empty',
      }
    },
   ...

感谢您抽出宝贵时间分享解决方案! 谢谢,请您填写这张表格,以便我们给您一些赃物?

感谢您的支持,并为我指明了正确的方向。
干杯,菲利普

iPad Pro iPad

No dia 07/09/2017,às17:17,Elmer Thomas [email protected] escreveu:

感谢您抽出宝贵时间分享解决方案! 谢谢您,请您填写这张表格,以便我们给您一些赃物?


您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看,或使该线程静音。

@froquette
我尝试实现相同的目的,并且您的答案解决了我之前的错误,但是以某种方式我无法使yarn run build得以执行。 我收到以下错误:

ERROR in pages/contact.92ae317ce1e8cd6ecca8.js from UglifyJs Unexpected token: punc (,) [./node_modules/@sendgrid/helpers/index.js:12,18][pages/contact.92ae317ce1e8cd6ecca8.js:2002,25]

您是否有相同的错误?如果是,您如何解决?

我正在使用npm(不是yarn),并且没有这种错误。

在2017年9月8日星期五上午11:54,Eljas [email protected]写道:

@froquette https://github.com/froquette
我尝试达成相同的目标,而您的答案修正了我之前的错误
但以某种方式,我无法使纱线运行构建得以执行。 我得到了
以下错误:

来自UglifyJs的pages / contact.92ae317ce1e8cd6ecca8.js中的错误意外
令牌:标点(,)[./node_modules/@sendgrid/helpers/index.js:12,18] [页面/
contact.92ae317ce1e8cd6ecca8.js:2002,25]

您是否有相同的错误?如果是,您如何解决?


您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看
https://github.com/sendgrid/sendgrid-nodejs/issues/432#issuecomment-328072989
或使线程静音
https://github.com/notifications/unsubscribe-auth/AGHRvMomseMLkiwd0TDy9P_Y69zNuAWoks5sgRzrgaJpZM4PGf2j

-
Cumprimentos,
菲利普·罗奎特

@jloproductions

看来您可能会遇到此问题。 您能否看一下并让我们知道? 谢谢!

最诚挚的问候,

埃尔默

嘿@thinkingserious
无法正常工作。 你能提供一些例子吗?

@froquette
您是否在项目中使用了Nuxt.js的入门模板?

我终于能够运行我的构建。 我将UglifyJsPlugin更改为BabiliPlugin( yarn add babili-webpack-plugin )。
这是我的nuxt.config.js:

const BabiliPlugin = require('babili-webpack-plugin')
module.exports = {
    ...
    build: {
        extend (config, ctx) {
          config.node = {
            console: true,
            fs: 'empty',
            net: 'empty',
            tls: 'empty'
          }
          if (ctx.dev && ctx.isClient) {
            config.module.rules.push({
              enforce: 'pre',
              test: /\.(js|vue)$/,
              loader: 'eslint-loader',
             exclude: /(node_modules)/
            })
          }
          if(!ctx.dev) {
            config.plugins = config.plugins.filter((plugin) => plugin.constructor.name !== 'UglifyJsPlugin')
            config.plugins.push(new BabiliPlugin())
           }
        },
    },
    ...
}

但是现在我的SendGrid API出现了一些CORS错误
Fetch API cannot load https://api.sendgrid.com/v3/mail/send. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://sendgrid.api-docs.io' that is not equal to the supplied origin. Origin 'https://my-url.com' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

我正在使用来自https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail的基本发送邮件示例。

@eljass
我确实发现您的UglifyJs问题很快就投入生产。 目前,我刚刚删除了UglifyJs插件,但是有更多时间可以尝试您的解决方案。 谢谢!

关于CORS问题。 我也在尝试消除此问题。 已经尝试将发送消息中的标头设置为sendgrid,但没有成功。 这是我使用的标题
标头:{
'Content-Type':'application / json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'POST,GET,OPTIONS',
'访问控制允许标题':'X-Requested-With'
}
---还没有成功!

你好@froquette @eljass

感谢您继续分享您的进度。 关于CORS,请参阅此文档

最诚挚的问候,

埃尔默

@thinkingserious
在该文档中未发现任何新内容。 基本的nodejs示例无法与sendgrid一起使用。 除了为API密钥设置环境变量以外,还有其他一些步骤吗?

@thinkingserious
在文档中也找不到太多。
我发现很奇怪的是,将我的sendgrid客户端代码存储在一个存储/动作中,应该仅仅是使用sendgrid API的服务器端代码,因此无法理解CORS问题。
我的应用程序托管在Heroku中,也许您知道我可以用来在Heroku中测试的一些示例。 肯定会有所帮助,因为我也会遇到这个问题。
干杯

@eljass @froquette

感谢您的跟进!

为了提供进一步的帮助,我需要了解有关您的设置的更多信息,以便我可以尝试复制。 您能否带我逐步了解如何复制您的设置? 一个简单的问候世界就足够了。

我的理论是,您试图通过前端/客户端与服务器端来利用SendGrid。 在这种情况下,CORS问题就是元凶。 我不了解在服务器端会发生CORS问题。

最诚挚的问候,

埃尔默

@thinkingserious
谢谢你的支持!
我正在尝试一条新路径,以确保与客户端和服务器代码完全分开。 将会在这里报告结果。
最好,菲利普

@froquette您是否找到解决此问题的方法?

是。 我现在正在使用Express和Nuxt。 (看到
https://github.com/nuxt-community/express-template)
我的Vue页面调用了一个存储操作,该操作使用REST API来调用
服务器端电子邮件功能。 工作正常。

在2017年11月1日星期三下午1:40,Thomas Ongeri [email protected]
写道:

@froquette https://github.com/froquette您是否找到了解决方案
这个问题?


您收到此邮件是因为有人提到您。
直接回复此电子邮件,在GitHub上查看
https://github.com/sendgrid/sendgrid-nodejs/issues/432#issuecomment-341108847
或使线程静音
https://github.com/notifications/unsubscribe-auth/AGHRvPzJLZvaMZA8Q5HUBwjLVc9q73CRks5syHTbgaJpZM4PGf2j

-
Cumprimentos,
菲利普·罗奎特

@froquette嗨,
我是第一次开始构建nuxtjs应用,并遇到了同样的障碍。 您能否提供完整的工作代码示例,以使其启动并运行?

@muhammedjenos不是Sendgrid,但是如果您正在使用Nuxt进行JAMstack并且只想捕获电子邮件,我建议您尝试使用Converkit -他们让您只需嵌入带有HTML和JS的电子邮件捕获表单就可以了

https://convertkit.com/features/forms

另外,我不隶属于Convertkit,只是以某种方式衡量自己的选择并遇到了这个问题

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

danielflippance picture danielflippance  ·  4评论

prasoonjalan picture prasoonjalan  ·  3评论

Loriot-n picture Loriot-n  ·  4评论

egges picture egges  ·  3评论

thinkingserious picture thinkingserious  ·  4评论