Tencent / wepy

小程序组件化开发框架
https://wepyjs.gitee.io/wepy-docs/
Other
22.54k stars 3.05k forks source link

thirdScriptError Cannot read property 'refs' of undefined; [Component] Lifetime Method Error @ pages/index#(anonymous) #2506

Closed YvongYang closed 4 years ago

YvongYang commented 4 years ago

Description

用 wepy init empty建的项目,npm run dev时总是会报如下错误。

VM6534:1 thirdScriptError
Cannot read property 'refs' of undefined; [Component] Lifetime Method Error @ pages/index#(anonymous)
TypeError: Cannot read property 'refs' of undefined
    at be.output.attached (http://127.0.0.1:24961/appservice/vendor.js:2470:22)
    at r.safeCallback (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1306940)
    at r.call (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1306833)
    at r (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1380371)
    at m (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1380696)
    at Function.y.pretendAttached (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1390145)
    at Module.Ue (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1487901)
    at Tt (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1588434)
    at http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1592274
    at xt (http://127.0.0.1:24961/appservice/__dev__/WAService.js:1:1592767)

Environment

具体: package.json:

"scripts": {
    "dev": "wepy build --watch --log trace",
    "build": "cross-env NODE_ENV=production wepy build --no-cache",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

"dependencies": {
    "@wepy/cli": "^2.0.0-alpha.22",
    "@wepy/core": "^2.0.0-alpha.9"
  },
  "devDependencies": {
    "@wepy/compiler-babel": "^2.0.3",
    "@wepy/compiler-less": "^2.0.3",
    "babel-eslint": "^7.2.1",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-export-extensions": "^6.22.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "cross-env": "^5.1.3",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.0.1",
    "less": "^3.8.1"
  }

project.config.json:

{
    "description": "A WePY project",
    "setting": {
        "urlCheck": true,
        "es6": false,
        "postcss": false,
        "minified": false
    },
    "compileType": "miniprogram",
    "appid": "touristappid",
    "projectname": "kaka",
    "miniprogramRoot": "weapp/",
    "simulatorType": "wechat",
    "simulatorPluginLibVersion": {},
    "condition": {}
}

wepy.config.js:

const path = require('path');
const prod = process.env.NODE_ENV === 'production'

module.exports = {
  wpyExt: '.wpy',
  eslint: true,
  build: {},
  compilers: {
    less: {
      compress: prod
    },
    /*sass: {
      outputStyle: 'compressed'
    },*/
    babel: {
      sourceMap: true,
      presets: [
        'env'
      ],
      plugins: [
        'babel-plugin-transform-class-properties',
        'transform-export-extensions',
        'syntax-export-extensions'
      ]
    }
  },
  plugins: [],
  appConfig: {
    noPromiseAPI: ['createSelectorQuery']
  },
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src'),
      Style: path.resolve(__dirname, 'src/styles/'),
      Util: path.resolve(__dirname, 'src/utility/')
    },
    aliasFields: ['wepy', 'weapp'],
    modules: ['node_modules']
  }
}

if (prod) {

  module.exports.cliLogs = false;

  delete module.exports.compilers.babel.sourcesMap;
  // 压缩sass
  // module.exports.compilers['sass'] = {outputStyle: 'compressed'}

  // 压缩less
  module.exports.compilers['less'] = {
    compress: true
  }

  // 压缩js
  module.exports.plugins = {
    uglifyjs: {
      filter: /\.js$/,
      config: {
      }
    },
    imagemin: {
      filter: /\.(jpg|png|jpeg)$/,
      config: {
        jpg: {
          quality: 80
        },
        png: {
          quality: 80
        }
      }
    }
  }
}

index.wpy:

<style lang="less">
</style>

<template>
  <div class="container">
    yang
  </div>
</template>

<script>
  import wepy from '@wepy/core';

  // 注册 Page
  wepy.page({
    data: {},
    onLoad() {
      console.log('onLoad')
    }
  });
</script>

<config>
{
  navigationBarTitleText: 'haha'
}
</config>
Gcaufy commented 4 years ago

抱歉现在才回复,刚才使用提供代码无法还原问题。看是否能提供完整代码包方便测试呢?

tf110347737 commented 4 years ago

请问解决了没有,我用wepy init empty myshop建立了一个项目,没有进行任何操作,就出现这个错误 image,不知道什么原因

YvongYang commented 4 years ago

抱歉现在才回复,刚才使用提供代码无法还原问题。看是否能提供完整代码包方便测试呢?

不好意思,因为公司的项目所以无法提供代码,我换成了standard模板就没有问题了。楼下的问题跟我之前出现的一样。

YvongYang commented 4 years ago

请问解决了没有,我用wepy init empty myshop建立了一个项目,没有进行任何操作,就出现这个错误 image,不知道什么原因

目前还不知道是什么原因,我换成了init standard模板就没问题了。

tf110347737 commented 4 years ago

你好,这个问题我已经解决,可能是开发者工具和wepy不兼容造成的,我换成了开发者工具的正式版搭配wepy1.7.3版本就没有这个问题了

tf110347737 commented 4 years ago

可以加一下你的联系方式吗,有好多问题想向你请教,我的QQ是1102347737

------------------ 原始邮件 ------------------ 发件人: "YvongYang"<notifications@github.com>; 发送时间: 2020年3月11日(星期三) 下午2:34 收件人: "Tencent/wepy"<wepy@noreply.github.com>; 抄送: "悠悠"<1102347737@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [Tencent/wepy] thirdScriptError Cannot read property 'refs' of undefined; [Component] Lifetime Method Error @ pages/index#(anonymous) (#2506)

请问解决了没有,我用wepy init empty myshop建立了一个项目,没有进行任何操作,就出现这个错误 ,不知道什么原因

目前还不知道是什么原因,我换成了init standard模板就没问题了。

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

Gcaufy commented 4 years ago

@YvongYang

这个问题修复了,可以重新init 一个 empty 项目试试看。 或者在自己的项目里升级 @wepy/compiler-babel 的版本。

tf110347737 commented 4 years ago

@YvongYang

这个问题修复了,可以重新初始化一个空项目尝试看。 或者在自己的项目里升级@ wepy / compiler-babel的版本。

是因为开发者工具和wepy框架不兼容的问题吗

Gcaufy commented 4 years ago

应该是 依赖的 babel 的版本的问题,导致编译出来的结果与预期有一点区别。 这里就升级了一个 compiler-babel, 兼容不同的的编译结果。 更详细的内容可以查看提交记录。