Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

getElementsByClassName, getElementsByTagName and getElementById TypeError: is not a function #17

Open
fabiopolimeni opened this issue Nov 13, 2018 · 3 comments

Comments

@fabiopolimeni
Copy link

fabiopolimeni commented Nov 13, 2018

Hi,

I am trying to use the plugin in its simplest form. Unfortunately, it seems that despite I can build an android app, as soon as I execute the code that contains one of these functions I get an error similar to this:

System.err: com.tns.NativeScriptException:
System.err: Calling js method onTouch failed
System.err: TypeError: DOM.getElementsByClassName is not a function

Neither of these importing methods work.

import * as DOM from "nativescript-dom"
//const DOM = require("nativescript-dom");

I use it like this
const navBarItems = DOM.getElementsByTagName("nav-bar-item");

This is my packege.json

"dependencies": {
    "nativescript-dom": "^2.0.2",
    "nativescript-geolocation": "^4.3.1",
    "nativescript-google-maps-sdk": "^2.6.1",
    "nativescript-pager": "^8.0.2",
    "nativescript-theme-core": "~1.0.4",
    "tns-core-modules": "4.2.1",
    "tslib": "^1.9.3"
  },
  "devDependencies": {
    "eslint": "^5.9.0",
    "nativescript-dev-typescript": "^0.7.4",
    "nativescript-dev-webpack": "^0.18.0",
    "tslint": "^5.11.0",
    "typescript": "~2.7.2"
  },

Any idea what can be causing this?
Thanks,
Fabio

@NathanaelA
Copy link
Owner

  1. Have you tried downloading the demo project from this repo and verifying it is not working?
  2. Which version of NativeScript? (tns --version)

@fabiopolimeni
Copy link
Author

  1. No, I was looking for some demo, but I couldn't find one. On this repo, I can only see the source code of the plugin itself. What am I missing?
  2. tns says 4.2.4

@hettiger
Copy link

Hi @NathanaelA I'm having a similar issue. Since migrating to NativeScript 4 the plugin no longer works when bundling with Webpack. (tns run ios still works flawlessly.)

I'm using getElementsByTagName() and I'm importing at the top of my app.module.ts file like this:

import "nativescript-dom";

I think the way I import it is the right one. I don't get the mentioned is not a function errors. However getElementsByTagName() always returns an empty array when bundling with Webpack like this:

tns run ios --bundle --env.uglify --env.aot

Can you please take a look at it? I'm pretty sure something's broken here. If you cannot reproduce it in a Webpack build: Can you please share where and how you import?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants