taro 微信开发者热重载功能对js/ts文件无效

kd3sttzy  于 2022-10-24  发布在  其他
关注(0)|答案(3)|浏览(1527)

相关平台

微信小程序

小程序基础库: 2.25.4
使用框架: React

复现步骤

taro init 一个新的项目,选择default模板,webpack5,less,typescript

yarn dev:weapp

微信开发者工具导入项目后,修改代码pages目录下的页面js文件,热重载在第一次生效后,后面的修改不再生效(必现)

期望结果

期望修改js文件热重载能生效,否则影响工程化开发效率

实际结果

热重载对js文件失效

环境信息

Taro CLI 3.5.1 environment info:
    System:
      OS: macOS 12.5
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 16.16.0 - /usr/local/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v16.16.0/bin/yarn
      npm: 8.11.0 - /usr/local/bin/npm

补充信息

期望官网能尽快修改这个bug~~~期待~~

gab6jxml

gab6jxml1#

Webpack5 的 runtime 不好兼容微信小程序的热更新(主要原因是无法操作闭包内的 module cache 对象,而兼容热更新需要清除 module cache 里对应模块的缓存)。所以需要再想想怎么处理。

oprakyz7

oprakyz72#

Webpack5 的 runtime 不好兼容微信小程序的热更新(主要原因是无法操作闭包内的 module cache 对象,而兼容热更新需要清除 module cache 里对应模块的缓存)。所以需要再想想怎么处理。

那是不是改成webpack4就可以了?我对比下webpack4和webpack的package.json,换下依赖包是不是就可以了

v1l68za4

v1l68za43#

在跑 npm run build:weapp -- --watch 时,似乎遇到了同样的问题

shensven@Luna ➜  test-taro git:(dev) ✗ npm run build:weapp -- --watch

> test-taro@1.0.0 build:weapp
> taro build --type weapp --watch

👽 Taro v3.5.5

Tips:
1. 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
$ NODE_ENV=production taro build --type weapp --watch
2. 建议开启持久化缓存功能,能有效提升二次编译速度,详情请参考: https://docs.taro.zone/docs/config-detail#cache。

Prebundle dependencies: 
     @taroify/core
     @taroify/core/button/style
     @tarojs/plugin-framework-react/dist/runtime
     @tarojs/plugin-platform-weapp/dist/runtime
     @tarojs/runtime
     @tarojs/taro
     jotai
     react
     react-dom
     react/jsx-runtime

▲ [WARNING] Constructing "FakePromise" will crash at run-time because it's an import namespace object, not a constructor [call-import-namespace]

node_modules/.pnpm/@taroify+core@0.1.0-alpha.1_ht7wm5ukezs2etiverp2gtdoka/node_modules/@taroify/core/hooks/use-function-interceptor.js:9:15:
9 │     return new FakePromise((resolve, reject) => {
╵                ~~~~~~~~~~~

Consider changing "FakePromise" to a default import instead:

node_modules/.pnpm/@taroify+core@0.1.0-alpha.1_ht7wm5ukezs2etiverp2gtdoka/node_modules/@taroify/core/hooks/use-function-interceptor.js:1:7:
1 │ import * as FakePromise from "promise";
│        ~~~~~~~~~~~~~~~~
╵        FakePromise

node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
{
moduleIdentifier: '/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/base-2f06bc5e.scss',
moduleName: './node_modules/.taro/weapp/prebundle/base-2f06bc5e.scss',
loc: '1:0',
message: "Module parse failed: Unexpected character '@' (1:0)\n" +
'You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\n' +
'> @import "./normalize";\n' +
'| @import "./animation";\n' +
'| @import "./clearfix";',
moduleId: './node_modules/.taro/weapp/prebundle/base-2f06bc5e.scss',
moduleTrace: [
{
originIdentifier: '/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js',
originName: './node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js',
moduleIdentifier: '/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/base-2f06bc5e.scss',
moduleName: './node_modules/.taro/weapp/prebundle/base-2f06bc5e.scss',
dependencies: [ { loc: '5:0-30' } ],
originId: './node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js',
moduleId: './node_modules/.taro/weapp/prebundle/base-2f06bc5e.scss'
},
{
originIdentifier: 'container entry (default) [["./react",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/react.js"]}],["./@taroify/core",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@taroify_core.js"]}],["./@taroify/core/button/style",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js"]}],["./jotai",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/jotai.js"]}],["./react/jsx-runtime",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/react_jsx-runtime.js"]}],["./@tarojs/runtime",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@tarojs_runtime.js"]}],["./@tarojs/plugin-framework-react/dist/runtime",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@tarojs_plugin-framework-react_dist_runtime.js"]}],["./@tarojs/plugin-platform-weapp/dist/runtime",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@tarojs_plugin-platform-weapp_dist_runtime.js"]}],["./@tarojs/taro",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@tarojs_taro.js"]}],["./react-dom",{"import":["/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/react-dom.js"]}]]',
originName: 'container entry',
moduleIdentifier: '/Users/shensven/Documents/GitHub/test-taro/node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js',
moduleName: './node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js',
dependencies: [ { loc: './@taroify/core/button/style[0]' } ],
originId: 'webpack/container/entry/taro_app_library',
moduleId: './node_modules/.taro/weapp/prebundle/@taroify_core_button_style.js'
}
],
details: undefined,
stack: "ModuleParseError: Module parse failed: Unexpected character '@' (1:0)\n" +
'You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\n' +
'> @import "./normalize";\n' +
'| @import "./animation";\n' +
'| @import "./clearfix";\n' +
'    at handleParseError (/Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/webpack@5.69.0/node_modules/webpack/lib/NormalModule.js:971:19)\n' +
'    at /Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/webpack@5.69.0/node_modules/webpack/lib/NormalModule.js:1090:5\n' +
'    at processResult (/Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/webpack@5.69.0/node_modules/webpack/lib/NormalModule.js:795:11)\n' +
'    at /Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/webpack@5.69.0/node_modules/webpack/lib/NormalModule.js:855:5\n' +
'    at /Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/loader-runner@4.3.0/node_modules/loader-runner/lib/LoaderRunner.js:407:3\n' +
'    at iterateNormalLoaders (/Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/loader-runner@4.3.0/node_modules/loader-runner/lib/LoaderRunner.js:233:10)\n' +
'    at /Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/loader-runner@4.3.0/node_modules/loader-runner/lib/LoaderRunner.js:224:4\n' +
'    at /Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/webpack@5.69.0/node_modules/webpack/lib/NormalModule.js:829:15\n' +
'    at Array.eval (eval at create (/Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)\n' +
'    at runCallbacks (/Users/shensven/Documents/GitHub/test-taro/node_modules/.pnpm/enhanced-resolve@5.10.0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)'
}

环境:

👽 Taro v3.5.5

  Taro CLI 3.5.5 environment info:
    System:
      OS: macOS 12.5.1
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
      npm: 8.19.1 - ~/.nvm/versions/node/v16.17.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.5 => 3.5.5 
      @tarojs/components: 3.5.5 => 3.5.5 
      @tarojs/helper: 3.5.5 => 3.5.5 
      @tarojs/plugin-framework-react: 3.5.5 => 3.5.5 
      @tarojs/plugin-platform-alipay: 3.5.5 => 3.5.5 
      @tarojs/plugin-platform-jd: 3.5.5 => 3.5.5 
      @tarojs/plugin-platform-qq: 3.5.5 => 3.5.5 
      @tarojs/plugin-platform-swan: 3.5.5 => 3.5.5 
      @tarojs/plugin-platform-tt: 3.5.5 => 3.5.5 
      @tarojs/plugin-platform-weapp: 3.5.5 => 3.5.5 
      @tarojs/react: 3.5.5 => 3.5.5 
      @tarojs/router: 3.5.5 => 3.5.5 
      @tarojs/runtime: 3.5.5 => 3.5.5 
      @tarojs/shared: 3.5.5 => 3.5.5 
      @tarojs/taro: 3.5.5 => 3.5.5 
      @tarojs/taro-h5: 3.5.5 => 3.5.5 
      @tarojs/webpack5-runner: 3.5.5 => 3.5.5 
      babel-preset-taro: 3.5.5 => 3.5.5 
      eslint-config-taro: 3.5.5 => 3.5.5 
      react: ^18.0.0 => 18.2.0

package.json

{
  "name": "test-taro",
  "version": "1.0.0",
  "private": true,
  "description": "测试-移动端",
  "templateInfo": {
    "name": "default",
    "typescript": true,
    "css": "sass"
  },
  "scripts": {
    "build:weapp": "taro build --type weapp",
    "build:swan": "taro build --type swan",
    "build:alipay": "taro build --type alipay",
    "build:tt": "taro build --type tt",
    "build:h5": "taro build --type h5",
    "build:rn": "taro build --type rn",
    "build:qq": "taro build --type qq",
    "build:jd": "taro build --type jd",
    "build:quickapp": "taro build --type quickapp",
    "dev:weapp": "npm run build:weapp -- --watch",
    "dev:swan": "npm run build:swan -- --watch",
    "dev:alipay": "npm run build:alipay -- --watch",
    "dev:tt": "npm run build:tt -- --watch",
    "dev:h5": "npm run build:h5 -- --watch",
    "dev:rn": "npm run build:rn -- --watch",
    "dev:qq": "npm run build:qq -- --watch",
    "dev:jd": "npm run build:jd -- --watch",
    "dev:quickapp": "npm run build:quickapp -- --watch",
    "doctor": "taro doctor",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "browserslist": [
    "last 3 versions",
    "Android >= 4.1",
    "ios >= 8"
  ],
  "author": "",
  "dependencies": {
    "@babel/runtime": "^7.7.7",
    "@taroify/core": "0.1.0-alpha.1",
    "@tarojs/components": "3.5.5",
    "@tarojs/helper": "3.5.5",
    "@tarojs/plugin-framework-react": "3.5.5",
    "@tarojs/plugin-platform-alipay": "3.5.5",
    "@tarojs/plugin-platform-jd": "3.5.5",
    "@tarojs/plugin-platform-qq": "3.5.5",
    "@tarojs/plugin-platform-swan": "3.5.5",
    "@tarojs/plugin-platform-tt": "3.5.5",
    "@tarojs/plugin-platform-weapp": "3.5.5",
    "@tarojs/react": "3.5.5",
    "@tarojs/router": "3.5.5",
    "@tarojs/runtime": "3.5.5",
    "@tarojs/shared": "3.5.5",
    "@tarojs/taro": "3.5.5",
    "@tarojs/taro-h5": "3.5.5",
    "jotai": "^1.8.2",
    "react": "^18.0.0",
    "react-dom": "^18.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.8.0",
    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
    "@tarojs/cli": "3.5.5",
    "@tarojs/webpack5-runner": "3.5.5",
    "@types/react": "^18.0.0",
    "@types/webpack-env": "^1.13.6",
    "@typescript-eslint/eslint-plugin": "^5.20.0",
    "@typescript-eslint/parser": "^5.20.0",
    "babel-preset-taro": "3.5.5",
    "eslint": "^8.12.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-taro": "3.5.5",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-react": "^7.8.2",
    "eslint-plugin-react-hooks": "^4.2.0",
    "prettier": "^2.7.1",
    "react-refresh": "^0.11.0",
    "stylelint": "^14.4.0",
    "typescript": "^4.1.0",
    "webpack": "5.69.0"
  },
  "engines": {
    "node": ">=16",
    "pnpm": ">=7"
  }
}

相关问题