Nativescript: Destructuring imports from `tns-core-modules` got Errors.

Created on 19 Jun 2017  Â·  5Comments  Â·  Source: NativeScript/NativeScript

Did you verify this is a real problem by searching [Stack Overflow]

Yes.

Tell us about the problem

Destructuring imports from tns-core-modules got Errors.

Which platform(s) does your issue occur on?

iOS

Please provide the following version numbers that your issue occurs with:

  • CLI: 3.0.3
  • Cross-platform modules: 3.0.1
  • Runtime(s): tns-ios: 3.0.1
  • Plugin(s): No

Please tell us how to recreate the issue in as much detail as possible.

I just tns create Project && cd Project, and then modify two auto-created example file to try to use ECMA6 syntax.

file:///app/tns_modules/tns-core-modules/globals/globals.js:30:38: JS ERROR SyntaxError: Importing binding name 'Observable' is not found.
// The original require(), works.
const Observable = require("data/observable").Observable;

// Import but not destructuring in the same line, works.
import observable from 'data/observable'
const Observable = observable.Observable

// Got `Importing binding name 'Observable' is not found.` Error here
import { Observable } from 'data/observable'
// Still got an error.
import { Observable } from 'tns-core-modules/data/observable'

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

I already re-create a clean project by tns create Project and just modify the files needed.
My Node version is v7.5.0

The files I've been modified:
https://gist.github.com/shirohana/1fb558ca139351470cb22f6ef1f0c906

Thanks first (๑• ω •๑)

ios question

All 5 comments

import observable from 'data/observable'
var Observable
({ Observable } = observable)

would work, too, but looks terrible :(

@shirohana the support for ES6 is discussed here. You might consider using TypeScript so you can use the newest language features.

Another solution for targeting ES6 in your javaScript project can be found here.

In my personal opinion, TS is giving you a much clear and readable syntax along with the modern JavaScript features. Not to mention it is a first class citizen for every Angular based application so you can give it a try.

Closing as a duplicate to the issues linked above.

Thanks for your suggestion ฅ' ω 'ฅ
it's relieved for me that I didn't screw up in the beginning...

I would try TypeScript after I read the documentation done,
thanks again and have a nice day (*ˇωˇ*人)

@shirohana if you want a fast glance of what a NativeScript TypeScript project looks like execute
tns creaste myFirstApp --tsc

From there the workflow is the same. Keep in mind that tns build or tns run will call the TypeScript transpiler and the code will be generated into pure JavaScript. So each *.ts file will have the respective &.js file when you build your project. Made changes only in the TypeScript files and the changes will be applied in the JavaScript files on re-build

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings