Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error when importing and using a core component in the template #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vallemar opened this issue Dec 7, 2022 · 2 comments · Fixed by #1051
Closed

Error when importing and using a core component in the template #1017

vallemar opened this issue Dec 7, 2022 · 2 comments · Fixed by #1051
Labels
V3 Issues related to V3

Comments

@vallemar
Copy link
Contributor

vallemar commented Dec 7, 2022

When you import a core component such as StackLayout and you are also using it in the template, the application fails with this error:

  JS: [Vue warn]: Unhandled error during execution of render function
  JS:   at <StackLayout row="1" class="bg" >
  JS:   at <CurrentTrip props=undefined >
  JS:   at <RouterView defaultRoute="/current_trip" >
  JS:   at <App>
  System.err: An uncaught Exception occurred on "main" thread.
  System.err: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function
  System.err: TypeError: Class constructor StackLayout cannot be invoked without 'new'
  System.err: File: (file: src\webpack:\abll-app-next\webpack\bootstrap:27:0)
  System.err:
  System.err: StackTrace:
  System.err: renderComponentRoot(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:919:0)
  System.err:   at componentUpdateFn(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5631:0)
  System.err:   at run(file: src\webpack:\abll-app-next\node_modules\@vue\reactivity\dist\reactivity.esm-bundler.js:187:0)
  System.err:   at instance.update(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5745:0)
  System.err:   at setupRenderEffect(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5759:0)
  System.err:   at mountComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5541:0)
  System.err:   at processComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5499:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5101:0)
  System.err:   at mountChildren(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5285:0)
  System.err:   at mountElement(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5195:0)
  System.err:   at processElement(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5178:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5098:0)
  System.err:   at mountChildren(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5285:0)
  System.err:   at mountElement(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5195:0)
  System.err:   at processElement(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5178:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5098:0)
  System.err:   at componentUpdateFn(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5638:0)
  System.err:   at run(file: src\webpack:\abll-app-next\node_modules\@vue\reactivity\dist\reactivity.esm-bundler.js:187:0)
  System.err:   at instance.update(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5745:0)
  System.err:   at setupRenderEffect(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5759:0)
  System.err:   at mountComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5541:0)
  System.err:   at processComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5499:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5101:0)
  System.err:   at mountChildren(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5285:0)
  System.err:   at mountElement(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5195:0)
  System.err:   at processElement(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5178:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5098:0)
  System.err:   at componentUpdateFn(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5638:0)
  System.err:   at run(file: src\webpack:\abll-app-next\node_modules\@vue\reactivity\dist\reactivity.esm-bundler.js:187:0)
  System.err:   at instance.update(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5745:0)
  System.err:   at setupRenderEffect(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5759:0)
  System.err:   at mountComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5541:0)
  System.err:   at processComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5499:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5101:0)
  System.err:   at componentUpdateFn(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5638:0)
  System.err:   at run(file: src\webpack:\abll-app-next\node_modules\@vue\reactivity\dist\reactivity.esm-bundler.js:187:0)
  System.err:   at instance.update(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5745:0)
  System.err:   at setupRenderEffect(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5759:0)
  System.err:   at mountComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5541:0)
  System.err:   at processComponent(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5499:0)
  System.err:   at patch(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:5101:0)
  System.err:   at render(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:6260:0)
  System.err:   at mount(file: src\webpack:\abll-app-next\node_modules\@vue\runtime-core\dist\runtime-core.esm-bundler.js:4456:0)
  System.err:   at app.mount(file: src\webpack:\abll-app-next\node_modules\nativescript-vue\dist\index.js:45:0)
  System.err:   at app.start(file: src\webpack:\abll-app-next\node_modules\nativescript-vue\dist\index.js:48:0)
  System.err:   at ./src/app.ts(file:///data/data/org.nativescript.abllapp/files/app/bundle.js:69:5)
  System.err:   at __webpack_require__(file: src\webpack:\abll-app-next\webpack\bootstrap:24:0)
  System.err:   at __webpack_exec__(file:///data/data/org.nativescript.abllapp/files/app/bundle.js:3318:39)
  System.err:   at (file:///data/data/org.nativescript.abllapp/files/app/bundle.js:3319:221)
  System.err:   at __webpack_require__.X(file: src\webpack:\abll-app-next\webpack\runtime\startup entrypoint:6:0)
  System.err:   at (file:///data/data/org.nativescript.abllapp/files/app/bundle.js:3319:47)
  System.err:   at (file:///data/data/org.nativescript.abllapp/files/app/bundle.js:3324:3)
  System.err:   at require(:1:266)
  System.err:

Example:

<script lang="ts" setup>
import {StackLayout} from "@nativescript/core";
</script>

<template>
  <Page actionBarHidden="true">
      <StackLayout>
      </StackLayout>
  </Page>
</template>
@rigor789
Copy link
Member

rigor789 commented Dec 7, 2022

This is somewhat expected behavior with script setup: https://vuejs.org/api/sfc-script-setup.html#top-level-bindings-are-exposed-to-template

Since the import matches the tag, and the component naming convention.

You could alias the import as a workaround:

import {StackLayout as NSCStackLayout} from "@nativescript/core";

@vallemar
Copy link
Contributor Author

vallemar commented Dec 7, 2022

@rigor789 I have imagined it, perfect, I close this problem and it is here for future questions!

@vallemar vallemar closed this as completed Dec 7, 2022
@rigor789 rigor789 added the V3 Issues related to V3 label Dec 7, 2022
@rigor789 rigor789 reopened this Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V3 Issues related to V3
Development

Successfully merging a pull request may close this issue.

2 participants