Can I use Back4App with Next.js?

176 views
Skip to first unread message

Rufus Godnou

unread,
Nov 22, 2019, 1:53:40 AM11/22/19
to Back4App
I want to Use Back4App in my Next.js project, but
if I do
import Parse from "parse/node"
I get this error
./node_modules/xmlhttprequest/lib/XMLHttpRequest.js
Module not found: Can't resolve 'child_process' in

and if I use
import Parse from "parse"
I get this error
It looks like you're using the browser version of the SDK in a node.js environment. You should require('parse/node') instead.
Error creating install object ReferenceError: localStorage is not defined
 
How could I get arround this.
Thanks

Ricardo Paiva

unread,
Nov 22, 2019, 7:15:40 AM11/22/19
to Rufus Godnou, Back4App
Hi Rufus,

Next can be used in browser or nodejs environments, but when using Parse you have to explicity use the right version. Try to do this:
// myParse.js
var isBrowser=new Function("try {return this===window;}catch(e){ return false;}");
var Parse = isBrowser() ? require('parse') : require('parse/node');
module.exports = Parse;

So, in your js file use:
const Parse = require('./myParse');


Regards,

  name     : “Ricardo Paiva", 
  company  : “Back4app, Inc.", 
  twitter  : “@back4app", 
  web      : [“www.back4app.com"] 


--
You received this message because you are subscribed to the Google Groups "Back4App" group.
To unsubscribe from this group and stop receiving emails from it, send an email to back4app+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/back4app/80483d2e-9d5a-48ca-ad61-fae76090e496%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages