0

clicke here to see pondjs folder inside node-modulesI've installed pondjs(https://www.npmjs.com/package/pondjs) using npm install pondjs --save in my react application. It's also present in package.json. I couldn't understand why in App. js when I'm doing :

import { TimeSeries , TimeRange} from 'pondjs';

it says module not installed and hence unable to recognise it's functions.

Also, I have a js file which contains lots of data in Object form and I'm trying to import that file in App.js using :

import pathtofile/inputdata.js';

and storing in the variable as below :

var input_data = data;

IS this the right way to do in react App.js file? Please suggest

Ashag
  • 837
  • 2
  • 15
  • 24

3 Answers3

2

As there are 2 parts to your question. I will answer them in order.

Your first question was you weren't able to call the methods of pondjs even though you installed it.

For that make sure that there is your pondjs folder inside the node_modules folder that will be created when you install some packages in your repository.

EDIT :

Are you only having issues with pondjs or are you facing issues with all packages?

If you can find the installed package in node_modules folder and is facing the same issue for all packages, upgrade npm. Your problem is that it doesn't search in the right folder. Try upgrading npm so that it places files in the right spots.

If it's only for pondjs issue might be with the package rather that with your npm package. Make sure you read documentation right and are doing in the right way.


Coming to your second problem.

Export the variable you want to access in the other file.

var obj = {
    a : [1, 2, 3, 4],
    b : { c : 'Hello World!' }
}

export var obj;

And call it like,

import { obj } from './path/to/the/file.js'

bharadhwaj
  • 2,059
  • 22
  • 35
  • I have added a picture which shows pondjs is present inside node-modules. – Ashag Jul 05 '17 at 06:25
  • in my app.js file, i can do something like this? var k = obj.a; – Ashag Jul 05 '17 at 07:08
  • yes, you can. once you import it into another file, it's just same as a variable you declared in that file. – bharadhwaj Jul 05 '17 at 08:27
  • any advice on pondjs thing? – Ashag Jul 05 '17 at 17:11
  • var obj = { a : [1, 2, 3, 4], b : { c : 'Hello World!' } } export var obj; if i do something like this, so when you hover on var obj it says duplicate declaration. Is it because while exporting your are again specifying var, so its creating a new variable. – Ashag Jul 05 '17 at 17:35
  • I suppose that's the problem with your code editor. Hope you are using ES6 for coding. If you are having problem with export here is a good reference for it https://stackoverflow.com/a/34842087/3978238 – bharadhwaj Jul 06 '17 at 07:17
  • @Ashag Regarding pondjs can you specify what's the actual error message? Can you add it in the question? – bharadhwaj Jul 06 '17 at 07:18
0

For pondjs, my code is working on Sumblime Text and Terminal. May be Webstorm IDE is not recognizing Pondjs or something.

Ashag
  • 837
  • 2
  • 15
  • 24
0

Use require instead of import.

const { TimeSeries, TimeRange } = require('pondjs');