当前位置: 首页 > 知识库问答 >
问题:

未定义HTMLElement-Nativescript vue

卓嘉良
2023-03-14

我现在要做的就是让项目运行。

我运行tns运行android

应用程序生成,但在启动应用程序并抛出错误时

没有定义HTMLElement

所以这一切都始于我试图引入新的nativescript主题核心(2.2.0)。我跟随了他们在几个地方张贴的指南。一切看起来都很好。然后我运行tns运行android,第一次得到HTMLElement未定义错误。

  • 我已经吹走了node_modules和平台文件夹
  • npm重建
  • tns安装
  • 我卸载了nativescript-cli

然后我决定重新开始,开始一个干净的项目。以下步骤如下:https://nativescript-vue.org/en/docs/getting-started/quick-start/

当我运行tns-run-android时,我仍然得到相同的HTMLElement-is-not-defined错误,即使我根本没有修改模板。

我不知道这是窃听器还是我做错了什么

tns—版本6.1.2

节点-v 12.10.0

npm-v 6.10.3

所以无论我现在做什么,我现在都得到了这个错误。。。

代码方面,就像我所说的,我得到这个错误的原因是对这个模板的重新购买:https://github.com/nativescript-vue/vue-cli-template

这里是堆栈。

User-MacBook-Pro:hello-world user$ tns run android
Searching for devices...
Preparing project...
Bundling application for entryPath ./main...
File change detected. Starting incremental webpack compilation...

webpack is watching the files…

[BABEL] Note: The code generator has deoptimised the styling of /Users/scottbaron/Mos-Commodo/social-platform/peak-app/peak-matching/node_modules/@vue/devtools/build/backend.js as it exceeds the max of 500KB.
Hash: d11e779b2f173a00da85
Version: webpack 4.27.1
Time: 13195ms
Built at: 11/02/2019 10:57:09 AM
                             Asset       Size   Chunks             Chunk Names
assets/images/NativeScript-Vue.png   8.22 KiB           [emitted]  
                         bundle.js   84.3 KiB   bundle  [emitted]  bundle
                      package.json  165 bytes           [emitted]  
                        runtime.js   71.4 KiB  runtime  [emitted]  runtime
               tns-java-classes.js    0 bytes           [emitted]  
                         vendor.js   9.45 MiB   vendor  [emitted]  vendor
Entrypoint bundle = runtime.js vendor.js bundle.js
[./ sync ^\.\/app\.(css|scss|less|sass)$] . sync nonrecursive ^\.\/app\.(css|scss|less|sass)$ 175 bytes {bundle} [built]
[./ sync recursive (?<!\bApp_Resources\b.*)\.(xml|css|js|(?<!\.d\.)ts|(?<!\b_[\w-]*\.)scss)$] . sync (?<!\bApp_Resources\b.*)\.(xml|css|js|(?<!\.d\.)ts|(?<!\b_[\w-]*\.)scss)$ 204 bytes {bundle} [built]
[./app.scss] 18.5 KiB {bundle} [optional] [built]
[./main.js] 1.96 KiB {bundle} [built]
[./package.json] 146 bytes {bundle} [optional] [built]
[./store.js] 142 bytes {bundle} [built]
    + 208 hidden modules
Webpack compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (android)
Building project...
Gradle build...
         + setting applicationId
         + applying user-defined configuration from /Users/scottbaron/Mos-Commodo/social-platform/peak-app/peak-matching/app/App_Resources/Android/app.gradle
         + using andorid X library androidx.legacy:legacy-support-v4:1.0.0
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: /Users/scottbaron/Mos-Commodo/social-platform/peak-app/peak-matching/node_modules/nativescript-socketio/platforms/android/fancylogger-release.aar
         + adding aar plugin dependency: /Users/scottbaron/Mos-Commodo/social-platform/peak-app/peak-matching/node_modules/tns-core-modules-widgets/platforms/android/widgets-release.aar
Project successfully built.
The build result is located at: /Users/scottbaron/Mos-Commodo/social-platform/peak-app/peak-matching/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Installing on device 89EY06CQP...
Successfully installed on device with identifier '89EY06CQP'.
Restarting application on device 89EY06CQP...
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: ReferenceError: HTMLElement is not defined
System.err: File: "file:///node_modules/@vue/devtools/build/hook.js:517:28
System.err: 
System.err: StackTrace: 
System.err:     Frame: function:'handleCopy', file:'file:///node_modules/@vue/devtools/build/hook.js:517:28
System.err:     Frame: function:'clone', file:'file:///node_modules/@vue/devtools/build/hook.js:637:11
System.err:     Frame: function:'', file:'file:///node_modules/@vue/devtools/build/hook.js:199:24
System.err:     Frame: function:'on', file:'file:///node_modules/@vue/devtools/build/hook.js:145:11
System.err:     Frame: function:'emit', file:'file:///node_modules/@vue/devtools/build/hook.js:179:17
System.err:     Frame: function:'devtoolPlugin', file:'file:///node_modules/vuex/dist/vuex.esm.js:54:14
System.err:     Frame: function:'Store', file:'file:///node_modules/vuex/dist/vuex.esm.js:356:4
System.err:     Frame: function:'./store.js', file:'file:///app/store.js:6:15
System.err:     Frame: function:'__webpack_require__', file:'file:///app/webpack/bootstrap:750:0
System.err:     Frame: function:'fn', file:'file:///app/webpack/bootstrap:120:0
System.err:     Frame: function:'', file:'file:///app/main.js:1:0
System.err:     Frame: function:'./main.js', file:'file:///data/data/com.moscommodo.peak/files/app/bundle.js', line: 339, column: 30
System.err:     Frame: function:'__webpack_require__', file:'file:///app/webpack/bootstrap:750:0
System.err:     Frame: function:'checkDeferredModules', file:'file:///app/webpack/bootstrap:43:0
System.err:     Frame: function:'webpackJsonpCallback', file:'file:///app/webpack/bootstrap:30:0
System.err:     Frame: function:'', file:'file:///data/data/com.moscommodo.peak/files/app/bundle.js', line: 2, column: 57
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err: 
System.err: 
System.err: ReferenceError: HTMLElement is not defined
System.err: 
System.err: StackTrace:
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function 
System.err: ReferenceError: HTMLElement is not defined
System.err: File: "file:///node_modules/@vue/devtools/build/hook.js:517:28
System.err: 
System.err: StackTrace: 
System.err:     Frame: function:'handleCopy', file:'file:///node_modules/@vue/devtools/build/hook.js:517:28
System.err:     Frame: function:'clone', file:'file:///node_modules/@vue/devtools/build/hook.js:637:11
System.err:     Frame: function:'', file:'file:///node_modules/@vue/devtools/build/hook.js:199:24
System.err:     Frame: function:'on', file:'file:///node_modules/@vue/devtools/build/hook.js:145:11
System.err:     Frame: function:'emit', file:'file:///node_modules/@vue/devtools/build/hook.js:179:17
System.err:     Frame: function:'devtoolPlugin', file:'file:///node_modules/vuex/dist/vuex.esm.js:54:14
System.err:     Frame: function:'Store', file:'file:///node_modules/vuex/dist/vuex.esm.js:356:4
System.err:     Frame: function:'./store.js', file:'file:///app/store.js:6:15
System.err:     Frame: function:'__webpack_require__', file:'file:///app/webpack/bootstrap:750:0
System.err:     Frame: function:'fn', file:'file:///app/webpack/bootstrap:120:0
System.err:     Frame: function:'', file:'file:///app/main.js:1:0
System.err:     Frame: function:'./main.js', file:'file:///data/data/com.moscommodo.peak/files/app/bundle.js', line: 339, column: 30
System.err:     Frame: function:'__webpack_require__', file:'file:///app/webpack/bootstrap:750:0
System.err:     Frame: function:'checkDeferredModules', file:'file:///app/webpack/bootstrap:43:0
System.err:     Frame: function:'webpackJsonpCallback', file:'file:///app/webpack/bootstrap:30:0
System.err:     Frame: function:'', file:'file:///data/data/com.moscommodo.peak/files/app/bundle.js', line: 2, column: 57
System.err:     Frame: function:'require', file:'', line: 1, column: 266
System.err: 
System.err: 
System.err: ReferenceError: HTMLElement is not defined
System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6465)
System.err:     at android.app.ActivityThread.access$1300(ActivityThread.java:219)
System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
System.err:     at android.os.Looper.loop(Looper.java:214)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
System.err: Caused by: com.tns.NativeScriptException: Error calling module function 
System.err: ReferenceError: HTMLElement is not defined
System.err: File: "file:///node_modules/@vue/devtools/build/hook.js:517:28
System.err: 

共有3个答案

甘学潞
2023-03-14

使用以下命令创建项目时:

vue init nativescript-vue/vue-cli-template <project-name>

不要安装vue-devols。我认为这与vue开发工具试图访问Nativescript中不存在的DOM有关。

勾炳
2023-03-14

@sidHeart指出的解决方案有效,但不会让你观察商店。触发此错误的原因是NativeScript没有DOM,因此没有用于HTMLElement的类型。一个临时的解决方案是将下面的行添加到由new webpack定义的对象中。在文件webpack.config.js中定义插件({})

HTMLElement: function() {
 return false;
},

因此,完整对象如下所示:

new webpack.DefinePlugin({
  'global.TNS_WEBPACK': 'true',
  TNS_ENV: JSON.stringify(mode),
  process: 'global.process',
  HTMLElement: function() {
    return false;
  },
}),


感谢Brandon Gohsman在他的文章中展示了这个解决方案。

蓝昊然
2023-03-14

我找到了解决方案,更新你的main.js文件

import store from './store' // <= this should be before VueDevtools 
import VueDevtools from 'nativescript-vue-devtools';
 类似资料:
  • 问题内容: 注意:根据 ECMAScript5.1,第15.1.1.3节,window.undefined是只读的。 现代浏览器正确地实现了这一点。 例如:Safari 5.1,Firefox 7,Chrome 20等。 Undefined仍可在以下位置更改:Chrome 14,… 原来,问题的原因是 如果“对象”中没有属性“ x”,则返回false。 我通过在两个Facebook函数中用规则相等

  • 问题内容: 我正在使用PHP版本5.3并尝试在我的代码中使用,但是出现错误: 我仍然可以连接到数据库。为什么不可用? 我正在使用PHP版本5.3。 问题答案: 更新 中提到的评论,一直以来5.5弃用: 自PHP 5.5起不推荐使用mysql扩展。应该改用mysqli或PDO扩展名。否决已在mysql_deprecation中确定,可以在此找到对该决定背后原因的讨论。 并 在PHP 7中删除 。 是

  • 问题内容: 我有一个简单的jquery click事件 以及在site.master中定义的jquery引用 我检查了脚本是否已正确解析,可以在Firebug中查看标记并直接查看脚本,因此必须找到我。但是,我仍然得到: $未定义 而且没有一个jQuery的作品。我还尝试了$(document).ready和jQuery等的各种变体。 这是.net 3.5上的MVC 2应用程序,我确定我真的很密集,

  • 问题内容: 我收到此错误消息, 这是我的标题。 以下是我的JavaScript代码 以下是HTML 我想在输入标签上显示日期选择器。 我正在使用Bootstrap V3.1。 问题答案: 在使用$或jQuery的脚本之前 添加jQuery库 , 以便可以在脚本中标识$。

  • null 下面是我的代码摘要: 和我的表格

  • 问题内容: 我一直看到说使用=>或.bind(this)的答案,但这些解决方案均无效。 解: 问题答案: 当你 与ES2015类语法,你需要你的动作处理程序绑定到你的类的上下文。 试试这个: 通常,最好不要在其中使用箭头函数或方法,因为它会在每次调用时生成该函数的新副本。将函数声明移到。 我个人更喜欢在这种情况下使用箭头函数作为类属性 它不是ES2015规范的一部分,但babel stage-0预