08-27-2022 14:38 - edited 08-27-2022 15:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-27-2022 14:38 - edited 08-27-2022 15:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Answered! Go to the Best Answer.

- Labels:
-
JavaScript
Accepted Solutions
08-27-2022 21:33 - edited 08-27-2022 21:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-27-2022 21:33 - edited 08-27-2022 21:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

08-27-2022 14:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-27-2022 14:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Here's a long-shot: try:
...from "./area.js";
Gondwana Software

08-27-2022 14:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-27-2022 14:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Also, don't you need to export Area? And you might need to watch case sensitivity.
Gondwana Software

08-27-2022 14:57 - edited 08-27-2022 16:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-27-2022 14:57 - edited 08-27-2022 16:44
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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. 🙂

08-27-2022 20:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-27-2022 20:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.

08-27-2022 21:33 - edited 08-27-2022 21:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-27-2022 21:33 - edited 08-27-2022 21:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Gondwana Software

08-27-2022 21:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-27-2022 21:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Thank you so much. That worked for the class as well (at least with a constructor and simple getter).
08-27-2022 21:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


08-27-2022 21:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Great! It had to be something simple but tricky at the same time.
Gondwana Software
08-28-2022 07:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

08-28-2022 07:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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.
