Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stripe__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor #1896

Closed
stylessh opened this issue Sep 7, 2023 · 12 comments
Closed

stripe__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor #1896

stylessh opened this issue Sep 7, 2023 · 12 comments
Assignees
Labels

Comments

@stylessh
Copy link

stylessh commented Sep 7, 2023

Describe the bug

I receive an error when importing stripe:

image
image

I'm using next 13 with app dir and latest version of stripe.

To Reproduce

  1. Create a next 13 app.
  2. Create a stripe.ts file to initialize the library.
  3. Try to use it in a server route.

Expected behavior

The library should return the expected Stripe object since it's not marking any apparent error.

image

Code snippets

No response

OS

Windows 11

Node version

Node v18.16.0

Library version

"stripe": "12.14.0"

API version

2022-11-15

Additional context

No response

@stylessh stylessh added the bug label Sep 7, 2023
@remi-stripe
Copy link
Contributor

@stylessh The webpack error makes me think you are importing/using the stripe-node library in your client-side code. The stripe-node library is used server-side for API requests with your Secret API key and it is not compatible with a browser environment. For client-side API requests you would use a separate library called Stripe.js that can either be imported directly or using an npm package and the different options are covered in our docs here.

If you're confident this is only happening with your server-side code we would need a way to quickly reproduce this end to end with the exact code you're using!

@remi-stripe remi-stripe self-assigned this Sep 8, 2023
@remi-stripe
Copy link
Contributor

@stylessh I paired with someone else on my team to see if they knew what could cause this and they mentioned you might need to change your tsconfig.json file from

    "moduleResolution": "bundler",
    "resolveJsonModule": true,

to

    "moduleResolution": "node",
    "resolveJsonModule": true,

@stylessh
Copy link
Author

stylessh commented Sep 8, 2023

@remi-stripe first, thanks for helping me!

I'm pretty sure i'm importing the library on server side, next.js is server first and it executes all the files on the server unless you explicitly set it to client. I'm gonna try changing the tsconfig en let you know

@stylessh
Copy link
Author

stylessh commented Sep 8, 2023

image

Already had those options 🥲

@remi-stripe
Copy link
Contributor

@stylessh can you give a simple end to end repro? A repo with all the info would help

@stylessh
Copy link
Author

stylessh commented Sep 8, 2023

Invited you to the repo, check the stripe branch

@stylessh
Copy link
Author

stylessh commented Sep 8, 2023

be sure to copy .env.example to .env.local keys

@stylessh
Copy link
Author

stylessh commented Sep 8, 2023

this is the video example of the user flow and error

@remi-stripe
Copy link
Contributor

@stylessh Can you make a clean public repo that has the exact information needed to reproduce the issue? Sorry for the hassle but I'm not the only person helping and getting a clean repro without any manual steps would help. It really should solely be loading stripe-node and nothing specific to your own code/project beyond reproducing the error

@stylessh
Copy link
Author

stylessh commented Sep 8, 2023

Hey, I just debugged the issue. I have a webpack custom rule to load the canvas.node module with the raw-loader.

image

This probably matched with a stripe file ending having .node. I changed the regex to match only canvas.node, seems to load the library now.

image

@remi-stripe
Copy link
Contributor

Glad you figured it out and thanks for taking the time to update us with the root cause/fix, that's really appreciated :)

@element-software
Copy link

Hey, I just debugged the issue. I have a webpack custom rule to load the canvas.node module with the raw-loader.

image

This probably matched with a stripe file ending having .node. I changed the regex to match only canvas.node, seems to load the library now.

image

Exactly the same issue I had, your fix worked for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants