0

I have added OneSignal to my NextJS app using yarn add onesignal-node and then imported it in my _app.js file like this import * as OneSignal from 'onesignal-node' but I get

error - ./node_modules/request/lib/har.js:3:0
Module not found: Can't resolve 'fs'

Can someone help. I can't even do a basic import without an error.

Thanks

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
MomasVII
  • 4,641
  • 5
  • 35
  • 52
  • 1
    Looks like you're trying to use a Node.js library on client-side code, which won't work as the code will run on the browser. Make sure you only use `onesignal-node` in server-only code, like `getStaticProps`/`getServerSideProps` or API routes. – juliomalves Aug 06 '21 at 22:29
  • Does this answer your question? [Module not found: Can't resolve 'fs' in Next.js application](https://stackoverflow.com/questions/64926174/module-not-found-cant-resolve-fs-in-next-js-application) – juliomalves Aug 06 '21 at 22:32

1 Answers1

0

Here's a blog post demonstrating how to add push notifications into your NextJS project.

https://onesignal.com/blog/how-to-integrate-onesignal-into-a-next-app/

Keep in mind that what you are doing is not going to work because you are trying to import a Node package that is only for the server-side.

If you want to learn more about our developers' community, take a look at this link https://onesignal.com/onesignal-developers and join us!

Patricio Vargas
  • 5,236
  • 11
  • 49
  • 100