尝试与 NestJS 实现 Stripe 集成时出现运行错误

问题描述 投票:0回答:1

我需要将 Stripe 集成到我的 Nestjs 应用程序中,但是一旦我实例 stripe,我就会收到以下错误:

npm run start:dev
[5:05:11 PM] Starting compilation in watch mode...



#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 169220804
#
#
#
#FailureMessage Object: 0x16b0c4ac8
 1: 0x104e4c0e0 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
 2: 0x105c00f24 V8_Fatal(char const*, ...) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
 3: 0x105088114 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
 4: 0x1051eefa8 v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2>>::GrowCapacity(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
 5: 0x1053c8644 v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
 6: 0x1056eb8ec Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
 7: 0x10a222f18
 8: 0x10a2273a4
 9: 0x10a225370
10: 0x1056d9a7c Builtins_SetPrototypeForEach [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
11: 0x109a6b424
12: 0x109a6a83c
13: 0x109a66d08
14: 0x109a68860
15: 0x109eb710c
16: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
17: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
18: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
19: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
20: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
21: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
22: 0x1056b0d4c Builtins_GeneratorPrototypeNext [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
23: 0x10567f578 Builtins_InterpreterEntryTrampoline [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
24: 0x1057339d8 Builtins_PromiseFulfillReactionJob [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
25: 0x1056a0f54 Builtins_RunMicrotasks [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
26: 0x10567d244 Builtins_JSRunMicrotasksEntry [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
27: 0x1050407b4 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
28: 0x105040be8 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
29: 0x105040cd4 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*, v8::internal::MaybeHandle<v8::internal::Object>*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
30: 0x105063438 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
31: 0x105063bd0 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
32: 0x104d34c48 node::InternalCallbackScope::Close() [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
33: 0x104d347c4 node::InternalCallbackScope::~InternalCallbackScope() [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
34: 0x104df1af0 node::fs::FileHandle::CloseReq::Resolve() [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
35: 0x104e06ce4 node::fs::FileHandle::ClosePromise()::$_0::__invoke(uv_fs_s*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
36: 0x104deb37c node::MakeLibuvRequestCallback<uv_fs_s, void (*)(uv_fs_s*)>::Wrapper(uv_fs_s*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
37: 0x10565da94 uv__work_done [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
38: 0x105661244 uv__async_io [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
39: 0x105672de4 uv__io_poll [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
40: 0x1056616d4 uv_run [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
41: 0x104d356c0 node::SpinEventLoop(node::Environment*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
42: 0x104e28800 node::NodeMainInstance::Run(int*, node::Environment*) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
43: 0x104e284ec node::NodeMainInstance::Run() [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
44: 0x104dc0370 node::Start(int, char**) [/Users/cesargomez/.nvm/versions/node/v16.20.2/bin/node]
45: 0x19ce14274 start [/usr/lib/dyld]
[1]    80633 trace trap  npm run start:dev

这是我的模块:

import { Module } from '@nestjs/common';
import { PaymentsService } from './payments.service';
import { PaymentsController } from './payments.controller';

@Module({
  controllers: [PaymentsController],
  providers: [PaymentsService],
})
export class PaymentsModule {}

控制器

import { Controller, Get, Post } from '@nestjs/common';
import { PaymentsService } from './payments.service';
import { ApiTags } from '@nestjs/swagger';

@ApiTags('Payment Integration')
@Controller('payments')
export class PaymentsController {
  constructor(private readonly paymentsService: PaymentsService) {}

  @Post('create-payment-session')
  createPaymentSession() {
    return 'createPaymentSession';
  }

  @Get('success')
  success() {
    return 'Payment successful';
  }
  @Get('cancel')
  cancel() {
    return 'Payment cancelled';
  }

  @Get('products')
  getAllProducts() {
    return this.paymentsService.getAllProducts();
  }

  @Post('payment-webhook')
  async stripeWebhook() {
    return 'stripeWebhook';
  }
}

服务

import { Injectable } from '@nestjs/common';
import Stripe from 'stripe';

@Injectable()
export class PaymentsService {
  private readonly stripe = new Stripe(process.env.STRIPE_API_SECRET_KEY, {
    apiVersion: '2024-09-30.acacia',
  });
  async getAllProducts() {
    const products = await this.stripe.products.list();
    return products.data;
  }
}

我刚刚开始集成我得到的这个。 这是我尝试过的一些方法,但 ATM 机没有任何作用:

  • 尝试使用不同的nodeJS版本,例如16.0.0、16.20.2、18.16.0、18.17.1
  • 使用
    NODE_OPTIONS="--max-old-space-size=8192" npm run start:dev
  • 运行终端

然后我从头开始创建一个 Nestjs 项目,只是为了测试条带实现,并且该项目没有任何问题,这意味着

npm start run:dev
可以正常工作,没有警告和/或错误。 所以我想可能与其他依赖项有关? 老实说,我不知道从哪里或如何开始解决这个问题,所以任何帮助将非常感激。

nestjs stripe-payments
1个回答
0
投票

我想我发现了错误。 Stripe 文档提到它可以在节点 12 或更高版本上运行,但为了修复它,我必须运行:

npm install @types/node@18 --save-dev

在我的 package.json 中,@types/node 是:
"@types/node": "^16.0.0"
。 一旦我运行命令,项目就会立即启动,没有错误

© www.soinside.com 2019 - 2024. All rights reserved.