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

taro cli 1.2.22升级到1.2.26后小程序运行报错 Cannot read property 'id' of undefined #2792

Closed
flyrui316 opened this issue Apr 16, 2019 · 2 comments
Assignees

Comments

@flyrui316
Copy link
Collaborator

flyrui316 commented Apr 16, 2019

问题描述
[问题描述:站在其它人的角度尽可能清晰地、简洁地把问题描述清楚]
taro cli 1.2.22升级到1.2.26后,原生小程序先运行taro convert,然后运行 npm run dev:weapp后,在原来小程序onLoad函数里面如果存在参数op,想获得op里面的值会报错,Cannot read property 'id' of undefined
复现步骤
[复现问题的步骤]
1.taro convert
2.npm run dev:weapp
3.运行编译后的代码

[或者可以直接贴源代码,能贴文字就不要截图]

// 这里可以贴代码
小程序源码
Page({
  data: {

  },
  onLoad: function (op) {
    let id = op.id
    console.log(id)
  }
})


taro convert后的代码:
import { Block } from '@tarojs/components'
import Taro from '@tarojs/taro'
import withWeapp from '@tarojs/with-weapp'

@withWeapp('Page')
class _C extends Taro.Component {
  state = {}
  componentWillMount = op => {
    let id = op.id
    console.log(id)
  }
  config = {}

  render() {
    return <Block>123</Block>
  }
}
/**
 * Created by ryan on 2019/4/16.
 */

export default _C


npm run dev:weapp后的代码
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };

var _dec, _class, _class2, _temp2;

var _index = require("../../../npm/@tarojs/taro-weapp/index.js");

var _index2 = _interopRequireDefault(_index);

var _index3 = require("../../../npm/@tarojs/with-weapp/index.js");

var _index4 = _interopRequireDefault(_index3);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _C = (_dec = (0, _index4.default)('Page'), _dec(_class = (_temp2 = _class2 = function (_Taro$Component) {
  _inherits(_C, _Taro$Component);

  function _C() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, _C);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = _C.__proto__ || Object.getPrototypeOf(_C)).call.apply(_ref, [this].concat(args))), _this), _this.$usedState = [], _this.state = {}, _this.componentWillMount = function (op) {
      var id = op.id;
      console.log(id);
    }, _this.config = {}, _this.$$refs = [], _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(_C, [{
    key: "_constructor",
    value: function _constructor(props) {
      _get(_C.prototype.__proto__ || Object.getPrototypeOf(_C.prototype), "_constructor", this).call(this, props);
    }
  }, {
    key: "_createData",
    value: function _createData() {
      this.__state = arguments[0] || this.state || {};
      this.__props = arguments[1] || this.props || {};
      var __isRunloopRef = arguments[2];
      ;
      Object.assign(this.__state, {});
      return this.__state;
    }
  }]);

  return _C;
}(_index2.default.Component), _class2.properties = {}, _class2.$$events = [], _temp2)) || _class);
/**
 * Created by ryan on 2019/4/16.
 */

exports.default = _C;

Component(require('../../../npm/@tarojs/taro-weapp/index.js').default.createComponent(_C, true));

期望行为
[这里请用简洁清晰的语言描述你期望的行为]
返回undefined,而不是报错
报错信息
thirdScriptError
Cannot read property 'id' of undefined;at "pages/pages/test/test" page lifeCycleMethod onLoad function
TypeError: Cannot read property 'id' of undefined
at BaseComponent._this.componentWillMount (http://127.0.0.1:41160/appservice/pages/pages/test/test.js:44:18)
at componentTrigger (http://127.0.0.1:41160/appservice/npm/@tarojs/taro-weapp/dist/index.js:3517:100)
at updateComponent (http://127.0.0.1:41160/appservice/npm/@tarojs/taro-weapp/dist/index.js:3755:5)
at H.initComponent (http://127.0.0.1:41160/appservice/npm/@tarojs/taro-weapp/dist/index.js:3559:3)
at H.weappComponentConf.methods.onLoad (http://127.0.0.1:41160/appservice/npm/@tarojs/taro-weapp/dist/index.js:3651:21)
at H. (http://127.0.0.1:41160/appservice/__dev__/WAService.js:1:983107)
at H.p.callPageLifeTime (http://127.0.0.1:41160/appservice/__dev__/WAService.js:1:982866)
at kt (http://127.0.0.1:41160/appservice/__dev__/WAService.js:1:998756)
at http://127.0.0.1:41160/appservice/__dev__/WAService.js:1:1001435
at It (http://127.0.0.1:41160/appservice/__dev__/WAService.js:1:1001
[这里请贴上你的完整报错截图或文字]

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

Taro CLI 1.2.26 environment info:
System:
OS: macOS 10.14.4
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.10.0 - ~/.nvm/versions/node/v8.10.0/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.7.0 - ~/.nvm/versions/node/v8.10.0/bin/npm
npmGlobalPackages:
typescript: 3.1.6

  • 报错平台 [h5, weapp]
    weapp
    补充信息
    [可选]
    [根据你的调查研究,出现这个问题的原因可能在哪里?]
@taro-bot
Copy link

taro-bot bot commented Apr 16, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Apr 17, 2019

CC @yuche

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants