admin管理员组

文章数量:1415697

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.

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.

Share Improve this question asked Sep 19, 2016 at 20:37 Samarth AgarwalSamarth Agarwal 2,1448 gold badges42 silver badges81 bronze badges 2
  • included parse js in html , ryt? – Ajay Narain Mathur Commented Sep 19, 2016 at 20:40
  • No, could you please tell me what should be the path of the src, I have tried ../node_modules/... but not working. – Samarth Agarwal Commented Sep 19, 2016 at 20:49
Add a ment  | 

2 Answers 2

Reset to default 5

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

  1. Install Parse ponent 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;)

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./DefinitelyTyped/tsd

本文标签: javascriptUsing Parse as a module in Angular2Stack Overflow