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.
Best AnswerIt 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.
Best AnswerAlso, don't you need to export Area? And you might need to watch case sensitivity.
Best AnswerThanks 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 AnswerSo, 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 AnswerIt 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.
Best AnswerThank you so much. That worked for the class as well (at least with a constructor and simple getter).
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.