Skip to content
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

[3.5.0] Cannot convert undefined or null to object #11911

Closed
aliuq opened this issue Jun 9, 2022 · 13 comments
Closed

[3.5.0] Cannot convert undefined or null to object #11911

aliuq opened this issue Jun 9, 2022 · 13 comments
Assignees
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@aliuq
Copy link
Contributor

aliuq commented Jun 9, 2022

相关平台

微信小程序

小程序基础库: 2.24.3
使用框架: Vue 3

复现步骤

npm run dev:weapp

期望结果

没有报错

实际结果

错误信息:Cannot convert undefined or null to object
VM746:7953 页面【pages/index/index]错误:
 TypeError: Cannot convert undefined or null to object
    at r.keys (<anonymous>)
    at Object../src/pages/index/index.vue (index.vue?66d5:10)
    at __webpack_require__ (webpack_bootstrap:19)
    at __webpack_exec__ (index.vue?46d7:1)
    at index.vue?46d7:1
    at Function.__webpack_require__.O (webpack_runtime_chunk loaded:25)
    at index.vue?46d7:1
    at webpackJsonpCallback (webpack_runtime_jsonp chunk loading:74)
    at index.js:3
    at y (WASubContext.js?t=wechat&s=1654759343828&v=2.24.3:2)(env: Windows,mp,1.06.2206020; lib: 2.24.3)

WAServiceMainContext.js:2 Uncaught FrameworkError 
 Cannot convert undefined or null to object 
 TypeError: Cannot convert undefined or null to object
    at r.keys (<anonymous>)
    at Object../src/pages/index/index.vue (http://127.0.0.1:32303/appservice/pages/index/index.js:97:10)
    at __webpack_require__ (http://127.0.0.1:32303/appservice/runtime.js:24:41)
    at __webpack_exec__ (http://127.0.0.1:32303/appservice/pages/index/index.js:135:61)
    at http://127.0.0.1:32303/appservice/pages/index/index.js:136:77
    at Function.__webpack_require__.O (http://127.0.0.1:32303/appservice/runtime.js:60:23)
    at http://127.0.0.1:32303/appservice/pages/index/index.js:137:56
    at webpackJsonpCallback (http://127.0.0.1:32303/appservice/runtime.js:330:39)
    at http://127.0.0.1:32303/appservice/pages/index/index.js:3:49
    at y (http://127.0.0.1:32303/appservice/__dev__/WASubContext.js?t=wechat&s=1654759343828&v=2.24.3:2:713505)(env: Windows,mp,1.06.2206020; lib: 2.24.3)

WAServiceMainContext.js:2 TypeError: Cannot convert undefined or null to object
    at r.keys (<anonymous>)
    at Object../src/pages/index/index.vue (index.vue?66d5:10)
    at __webpack_require__ (webpack_bootstrap:19)
    at __webpack_exec__ (index.vue?46d7:1)
    at index.vue?46d7:1
    at Function.__webpack_require__.O (webpack_runtime_chunk loaded:25)
    at index.vue?46d7:1
    at webpackJsonpCallback (webpack_runtime_jsonp chunk loading:74)
    at index.js:3
    at y (WASubContext.js?t=wechat&s=1654759343828&v=2.24.3:2)(env: Windows,mp,1.06.2206020; lib: 2.24.3)

image

相关依赖

package.json
"dependencies": {
  "@babel/runtime": "^7.18.3",
  "@tarojs/components": "3.5.0-beta.2",
  "@tarojs/runtime": "3.5.0-beta.2",
  "@tarojs/taro": "3.5.0-beta.2",
  "vue": "^3.2.37"
},
"devDependencies": {
  "@babel/core": "^7.8.0",
  "@iconify-json/carbon": "^1.1.5",
  "@iconify-json/mdi": "^1.1.19",
  "@tarojs/cli": "3.5.0-beta.2",
  "@tarojs/plugin-framework-vue3": "3.5.0-beta.2",
  "@tarojs/plugin-html": "3.5.0-beta.2",
  "@tarojs/webpack5-runner": "3.5.0-beta.2",
  "@types/webpack-env": "^1.17.0",
  "@vue/babel-plugin-jsx": "^1.0.6",
  "@vue/compiler-sfc": "^3.2.37",
  "babel-preset-taro": "3.5.0-beta.2",
  "eslint": "^8.16.0",
  "eslint-config-taro": "3.5.0-beta.2",
  "prettier": "^2.6.2",
  "stylelint": "14.8.5",
  "typescript": "^4.7.3",
  "vue-loader": "^17.0.0",
  "webpack": "^5.69.0"
}

环境信息

👽 Taro v3.5.0-beta.2


  Taro CLI 3.5.0-beta.2 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.19.1 - C:\scoop_soft\apps\nvm\current\nodejs\nodejs\node.EXE
      Yarn: 1.22.19 - C:\scoop_soft\apps\yarn\current\bin\yarn.CMD
      npm: 6.14.16 - C:\scoop_soft\apps\nvm\current\nodejs\nodejs\npm.CMD

补充信息

原来是3.4.10的项目,升级后出现报错,能正常跑通,就是有错误信息

@taro-bot2 taro-bot2 bot added F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Jun 9, 2022
@AdvancedCat
Copy link
Member

可以提供一下可复现的 DEMO

@aliuq
Copy link
Contributor Author

aliuq commented Jun 9, 2022

可以提供一下可复现的 DEMO

我没有另开项目复现,不知道其他人旧项目升级的有没有这样的问题

@AdvancedCat
Copy link
Member

可以把 r.keys 上下几行代码贴出来看下,或者你打断点看下上下文信息

@aliuq
Copy link
Contributor Author

aliuq commented Jun 9, 2022

可以把 r.keys 上下几行代码贴出来看下,或者你打断点看下上下文信息

image

这个地方的cache确实应该是undefinedObject.keys(undefined)

@AdvancedCat
Copy link
Member

@Chen-jj 看截图应该是 webpack5 的构建产物不再使用 __webpack_require__.c 存储 cache 了,改为 __webpack_module_cache__

@aliuq
Copy link
Contributor Author

aliuq commented Jun 9, 2022

@AdvancedCat 我装的webpack版本是5.69.0啊,node_modules都删了好多遍了

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 13, 2022

@Chen-jj 看截图应该是 webpack5 的构建产物不再使用 __webpack_require__.c 存储 cache 了,改为 __webpack_module_cache__

image

截图是之前为了兼容小程序热更新注入的 hack 代码,应该是 webpack 版本升级后 hack 代码要调整,我看看

@Chen-jj Chen-jj self-assigned this Jun 13, 2022
@aliuq
Copy link
Contributor Author

aliuq commented Jun 14, 2022

@Chen-jj 啥时候会更新呀

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 15, 2022

webpack5 的 runtime 不好 hack,暂时不支持对小程序开发者工具热更新。

@Chen-jj Chen-jj closed this as completed Jun 15, 2022
@aliuq
Copy link
Contributor Author

aliuq commented Jun 15, 2022

@Chen-jj 好吧,这个地方是不是应该做个条件判断

const hmr = !options.hot ? '' : `if (process.env.NODE_ENV !== 'production') {
const cache = __webpack_require__.c
Object.keys(cache).forEach(item => {
if (item.indexOf('${options.name}') !== -1) delete cache[item]
})
}`

一个不想看到满屏错误信息的临时方案,修改文件 node_modules\@tarojs\taro-loader\lib\page.js 第29行,然后每个页面需要触发热更新一次

if (process.env.NODE_ENV !== 'production') {
- const cache = __webpack_require__.c
+ const cache = __webpack_require__.c || {}
  Object.keys(cache).forEach(item => {
    if (item.indexOf('${options.name}') !== -1) delete cache[item]
  })
}

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 15, 2022

@aliuq 可以的~欢迎来个 pr 哈

@ZhuQinPeng
Copy link

同样遇到这个问题,感谢 @aliuq 的解决办法,但是还有个问题就是运行yarn build:weapp还是有报错,如下:
7e54cf422964ff17960f7fa31f05bac
应该怎么解决呢,谢谢
@Chen-jj

@yoyo837
Copy link
Contributor

yoyo837 commented Oct 10, 2022

上复现吧, 有助于解决问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-vue3 Framework - Vue 3 T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

5 participants