Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Parse as a module in Angular2

I am new to Angular2 and TypeScript and I am trying to import Parse into my application. So I have installed parse as a node module using npm install parse --save and I can see the parse folder inside the node_modules folder. Now, in my app.ts file, I am trying the following code but I don't know why is this giving errors.

import {Parse} from 'parse';

It gives the error that it

cannot find the module 'parse'

.

I also tried the following code,

import {} from 'parse'

and it works without errors but I don't know how do I use the Parse object now.

Any help or suggestion is highly appreciated.

Thanks in advance.

like image 347
Samarth Agarwal Avatar asked Mar 04 '26 05:03

Samarth Agarwal


2 Answers

I had the same problem (Here is it solved). I put the step by step how i solved it here.

  1. Install Parse component to the project

    npm install parse --save
    
  2. Install Parse types

    npm install @types/parse --save
    
  3. import Parse module

    const Parse: any = require('parse');
    
  4. use Parse module

    Parse.initialize("key");
    ...
    

Hope it helps;)

like image 166
Jan Kuta Avatar answered Mar 06 '26 19:03

Jan Kuta


You need to declare the parse module so that is recognized by typescript.

You can declare the parsemodule yourself with something like this:

declare module 'parse' {
    var parse: any;
    export { parse };
    export default parse;
}

Or you can use the typing definitions provided by Definitely Typed: https://github.com/DefinitelyTyped/tsd

like image 44
Guilherme Meireles Avatar answered Mar 06 '26 19:03

Guilherme Meireles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!