【问题标题】:Nativescript-vue + Typescript - HMR not working on Vue Class ComponentNativescript-vue + Typescript - HMR 不适用于 Vue 类组件
【发布时间】:2020-07-29 00:09:25
【问题描述】:

环境

  • CLI:6.5.0
  • 跨平台模块:6.5.1
  • Android 运行时:6.5.0
  • iOS 运行时:6.5.0

描述错误

当使用 vue 类组件样式 + typescript 保存任何文件时,它根本不会更新。给我以下错误:

File change detected. Starting incremental webpack compilation...
Successfully transferred bundle.609c813aedb0d81fb57e.hot-update.js on device emulator-5554.
Successfully transferred 609c813aedb0d81fb57e.hot-update.json on device emulator-5554.
JS: HMR: Checking for updates to the bundle with hmr hash 609c813aedb0d81fb57e.
JS: HMR: Ignored an update to unaccepted module: 
JS: HMR:          ➭ ./routes.ts
JS: HMR:          ➭ ./main.ts
JS: HMR: Cannot apply update with hmr hash 609c813aedb0d81fb57e.
JS: HMR: Aborted because ./routes.ts is not accepted
JS: Update propagation: ./routes.ts -> ./main.ts
Refreshing application on device emulator-5554...
Successfully transferred bundle.js on device emulator-5554.
Successfully transferred runtime.js on device emulator-5554.
Successfully transferred vendor.js on device emulator-5554.
JS: HMR: Cannot apply update. A previous update aborted. Application needs to be restarted in order to apply the changes.
Restarting application on device emulator-5554...

这会导致整个应用程序重新启动,而没有 HRM 更新。

复制

基于nativescript 博客NativeScript-Vue with Class Components 更多示例见链接。

  1. npm install -g @vue/cli @vue/cli-init
  2. vue init nativescript-vue/vue-cli-template hmrbug。 (选择打字稿)
  3. npm i vue-class-component
  4. npm i vue-property-decorator

下一步: 创建以下模板:

<Label text="Hello" textWrap="true" />

然后在文本中添加一个hello

<Label text="Hello Hello" textWrap="true" />

检查错误。

预期行为

使用著名的 HMR 无需重启整个 App。我认为这是一个严重的问题或错误,因为它会在等待应用程序重新启动时降低您作为开发人员的工作效率。

【问题讨论】:

  • 我认为这是 Github 问题,我相信 Vue + HMR 存在已知问题,我建议您禁用 HMR (--no-hmr)。当然,它的效率较低,但总比在 HMR 时不时地重新加载中间被击中要好。
  • 谢谢,我想我会继续使用--no-hmr。

标签: typescript nativescript nativescript-vue


【解决方案1】:

请使用tns debug android --no-hmr

在 nativescript-vue 和 HMR 中没有保证。 HMR 只能在更改样式文件时使用。

我个人使用

我仅将tns debug android 用于样式。如果我进行任何其他更改,我将不信任 HMR。

我添加了一个名为 yarn devan 的纱线脚本来加快打字过程。

我在 package.json 文件中添加了以下几行

{
  "scripts": {
    "dev": "tns debug android",
    "devan": "tns debug android --no-hmr",
    "devin": "tns debug ios --no-hmr",
    "un": "adb uninstall com.domain.yourapp"
  },
}

如果您在 nativescript-vue 项目中使用 typecipt 文件,您将始终看到 HMR 错误消息。

JS: HMR: Checking for updates to the bundle with hmr hash 7d5f6392d6103f1496e6.
JS:  WARN  HMR: Ignored an update to unaccepted module: 
JS:  WARN  HMR:          ➭ ./routes/index.ts
JS:  WARN  HMR:          ➭ ./main.ts
JS:  ERROR  HMR: Cannot apply update with hmr hash 7d5f6392d6103f1496e6.
JS:  ERROR  HMR: Aborted because ./routes/index.ts is not accepted
JS: Update propagation: ./routes/index.ts -> ./main.ts

【讨论】:

  • 感谢您的贡献!! .令人失望的是,nativescript 还没有带有 vue 的 HRM :C.
【解决方案2】:

我的 Nativescript-Vue + Typescript 与 HMR 项目一起工作。请注意(根据严格自己,NS-Vue 的创建者),在使用样式时最好启用 HMR。

这是解决我的问题的问题和线程:https://github.com/Lyduz/nitibo/issues/19

【讨论】:

    猜你喜欢
    • 2018-12-08
    • 2020-03-20
    • 2017-11-08
    • 2020-12-31
    • 2017-10-26
    • 2020-10-19
    • 1970-01-01
    • 2019-04-19
    • 2020-12-07
    相关资源
    最近更新 更多