Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

External pojo in OS 6+

ANSWERED

Hello,

I am finally getting around to update my grade app for the newer OSs. I am stuck because I use a Pojo not in index.js, and when I try to construct a class of it, I get the following error.

 

TypeError: Cannot create property 'code' on boolean 'true'
Details:
    watchFiles: /project/app/index.js,tslib,/project/app/views/single.js
Build failed.

 

 

Here is a sample pojo (area.js).

 

class Area {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
export function calcArea() {
    let area= this.height * this.width;
    console.log(area);
  }
}

 

 This is what I am trying to do to access it in index.js.

 

import {Area} from "area.js";

const myCalculator = new Area(3,2);
myCalculator.calcArea;

 

  Can anyone help me? This works if I move the class to index.js, but my actual pojo is a lot more complex so I would rather keep it in its own file. Thank you all in advance. 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

It works for me if you import from "./hello.js", assuming that file is in the same directory as index.js.

Admittedly I'm using CLI and not Studio. Studio's behaviour may depend on what SDK is being targeted, since I think the ./ requirement changed sometime.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
8 REPLIES 8

Here's a long-shot: try:

...from "./area.js";
Peter McLennan
Gondwana Software
Best Answer
0 Votes

Also, don't you need to export Area? And you might need to watch case sensitivity.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thanks for the reply.

That did not work, and neither did dropping the .js.

 

It seems to not be importing the constructor correctly, but I am not certain.

 

I did not need to export the class in the older sdk, but tried that here to no avail. I did have the correct case on my computer, I just messed it up when posting above. I fixed it in both though. If the case is off, the project builds, but obviously, the code does not work. 🙂

Best Answer
0 Votes

So, I am not able to import a function either.

If I try the following...

hello.js

export function hi(){
return 'Hello World'
}

index.js

import {hi as hello} from "hello.js";
console.log(hello());

I get the same error as above. I am using the web IDE, not my offline one.

Best Answer
0 Votes

It works for me if you import from "./hello.js", assuming that file is in the same directory as index.js.

Admittedly I'm using CLI and not Studio. Studio's behaviour may depend on what SDK is being targeted, since I think the ./ requirement changed sometime.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you so much. That worked for the class as well (at least with a constructor and simple getter).

Best Answer

Great! It had to be something simple but tricky at the same time.

Peter McLennan
Gondwana Software
Best Answer

Yes, definitely, it almost always is. I got it working with the original class. all the functions are working now as well. it really was just the syntax of the import. Thank you again.

Best Answer