4

I am attempting to use a Parse server and am currently running into issues with initializing Parse in javascript and pointing to the correct serverURL. Curious if anyone else has had any luck doing this with Angular2 yet?

3 Answers 3

8

For frameworks that use typescript (ex. angular 2, ionic 2 & 3),

To solve the typescript read-only error:

Typescript Error

Cannot assign to 'serverURL' because it is a constant or a read-only property.

Parse.serverURL = 'http://localhost:1337/parse';

Use (Parse as any) instead of Parse to set the value of serverUrl such as:

import * as Parse from 'parse';

Parse.initialize('appId', 'jsKey');  // use your appID & your js key
(Parse as any).serverURL = 'http://localhost:1337/parse'; // use your server url

This require parse and @types/parse to be installed:

npm install --save @types/parse parse 
Sign up to request clarification or add additional context in comments.

Comments

3

A bit late but I've found the trick when the typescript throws a Cannot assign to 'serverURL' because it is a constant or a read-only property

// Use parse with typescript
import * as Parse from 'parse';
// To set the server URL
let parse = require('parse');

Now you have access to parse.serverUrl, which is the same as Parse.serverUrl except that the TS definition will throw a read-only error.

2 Comments

When I use require('parse'), tons of errors appear upon compiling.
now you have to use const instead of let. This solved my issue.
1

I'm using Parse server within an Angular 1 application, but the code works for both. I'm initializing Parse in a own Parse service, which provides some handy helper methods. But I think it doesn't matter where you run this code.

var appId = 'appId';
var jsKey = 'jsKey'; // I think this is not used anymore
Parse.initialize(appId, jsKey);
Parse.serverURL = 'yourNewServerUrl.com';

2 Comments

I have my own parse.service.ts file. But when I try Parse.serverURL = environment.ParseServerUrl; I receive such err - Cannot assign to 'serverURL' because it is a constant or a read-only property. Any thoughts? Thx
@VitaliiTrachenko (Parse as any).serverURL = 'parse_url'; try this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.