I'm new to NativeScript and I'd like to fetch a JSON that is a part of my projet.
How do I do so?
The following failed:
app/data/util.js
import json from "../data/urls"; // Attempting to fetch urls.json
As a result:
com.tns.NativeScriptException: Error calling module function
Error: Cannot find module '../data/urls'
File: (file:///data/data/org.nativescript.preview/files/app/bundle.js:435:120)
StackTrace:
webpackMissingModule(file:///data/data/org.nativescript.preview/files/app/bundle.js:435:45)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:435:131)
at ./data/utils.js(file:///data/data/org.nativescript.preview/files/app/bundle.js:504:30)
at __webpack_require__(file:///data/data/org.nativescript.preview/files/app/runtime.js:751:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at ../node_modules/babel-loader/lib/index.js!../node_modules/vue-loader/lib/index.js?!./components/Home.vue?vue&type=script&lang=js&(file:///data/data/org.nativescript.preview/files/app/bundle.js:9:69)
at __webpack_require__(file:///data/data/org.nativescript.preview/files/app/runtime.js:751:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at ./components/Home.vue?vue&type=script&lang=js&(file:///data/data/org.nativescript.preview/files/app/bundle.js:397:187)
at __webpack_require__(file:///data/data/org.nativescript.preview/files/app/runtime.js:751:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at ./components/Home.vue(file:///data/data/org.nativescript.preview/files/app/bundle.js:345:92)
at __webpack_require__(file:///data/data/org.nativescript.preview/files/app/runtime.js:751:30)
at fn(file:///data/data/org.nativescript.preview/files/app/runtime.js:121:20)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:246:74)
at ./app.js(file:///data/data/org.nativescript.preview/files/app/bundle.js:306:30)
at __webpack_require__(file:///data/data/org.nativescript.preview/files/app/runtime.js:751:30)
at checkDeferredModules(file:///data/data/org.nativescript.preview/files/app/runtime.js:44:23)
at webpackJsonpCallback(file:///data/data/org.nativescript.preview/files/app/runtime.js:31:19)
at (file:///data/data/org.nativescript.preview/files/app/bundle.js:2:57)
at require(:1:266)
Error: Cannot find module '../data/urls'
at com.tns.Runtime.runModule(Native Method)
at com.tns.Runtime.runModule(Runtime.java:662)
at com.tns.Runtime.run(Runtime.java:654)
at com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6158)
at android.app.ActivityThread.access$1200(ActivityThread.java:235)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6986)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
No matter if I attempt to fetch ~/data/urls
or ../data/urls
, the error is the same (with the minor path difference)
Later on, I ran into this question, but I'm pretty sure that there's a simpler to way to fetch a JSON of the current project, right?