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

升级到2.0.0-beta.10,统一接口的多端文件多端脚本逻辑出错 #5175

Closed
licanbluesea opened this issue Dec 24, 2019 · 8 comments
Assignees

Comments

@licanbluesea
Copy link

问题描述

image
如图所示为getTopStatus文件夹跨端的脚本文件结构,在组件引用并调用方法时出现,./src/components/top/index.weapp.js
Module not found: Can't resolve '@src/utils/getTopStatus/index' in '/taro-lab/src/components/top'
编译失败的情况。

复现步骤

  1. 多端组件调用正常,
    image
import Taro, { Component } from '@tarojs/taro';
import { View, Button, Text } from '@tarojs/components'
import { observer, inject } from '@tarojs/mobx'
import Top from "@src/components/top"; //调用并编译运行成功

import './index.less'

class Index extends Component {

  config = {
    navigationBarTitleText: ' ...',
    navigationStyle: 'custom'
  }
  render () {
    return (
      <View className='index'>
        <Top >test</Top>
      </View>
    )
  }
}

export default Index
  1. 多端脚本逻辑编译时失败
    image
import Taro, {Component} from '@tarojs/taro'
import {View} from '@tarojs/components'
import getTopStatus from "@src/utils/getTopStatus/index";
import './index.less';


export default class Top extends Component {
  render() {
    // eslint-disable-next-line no-undef
    const flag = wx.getSystemInfoSync().version.split('.')[0] >= 7 ? true : false;
    const {children} = this.props;
    const menuStatus = getTopStatus();

    const env = process.env.TARO_ENV;
    return flag ? (
      <View className='top-root' titleStyle='screen' style={{
        paddingBottom: `${menuStatus.paddingBottom}px`,
        paddingTop: `${menuStatus.paddingTop}px`
      }}
      >
        <View style={{background: '#000', textAlign: 'center', color: '#fff', display: 'flex'}}>
          <View style={{
            background: "#ddd",
            width: `${menuStatus.width + 20}px`,
            height: `${menuStatus.height}px`
          }}
          >{env} menu</View>
          {children}
        </View>
      </View>
    ) : ""
  }
}
import getTopStatus from "@src/utils/getTopStatus/index";  //调用并编译运行失败
import getTopStatus from "@src/utils/getTopStatus";  //调用并编译运行失败
import getTopStatus from "@src/utils/getTopStatus/index.weapp";  //调用并编译运行成功

期望行为

无论执行以下代码段都运行成功

import getTopStatus from "@src/utils/getTopStatus/index";  
import getTopStatus from "@src/utils/getTopStatus";  

报错信息

./src/components/top/index.weapp.js
Module not found: Can't resolve '@src/utils/getTopStatus/index' in '/taro-lab/src/components/top'
编译失败的情况。

系统信息

Taro CLI 2.0.0-beta.10 environment info:
    System:
      OS: macOS 10.15.2
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.13.0 - /usr/local/bin/node
      Yarn: 1.19.1 - /usr/local/bin/yarn
      npm: 6.11.3 - /usr/local/bin/npm
    npmPackages:
      @tarojs/async-await: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/components: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/mini-runner: ^2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/mobx: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/mobx-h5: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/mobx-rn: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/plugin-babel: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/plugin-csso: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/plugin-less: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/plugin-uglifyjs: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/rn-runner: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/router: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro-alipay: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro-h5: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro-qq: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro-swan: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro-tt: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/taro-weapp: 2.0.0-beta.10 => 2.0.0-beta.10 
      @tarojs/webpack-runner: 2.0.0-beta.10 => 2.0.0-beta.10 
      eslint-config-taro: 2.0.0-beta.10 => 2.0.0-beta.10 
      eslint-plugin-taro: 2.0.0-beta.10 => 2.0.0-beta.10 
      nerv-devtools: ^1.4.0 => 1.5.6 
      nervjs: ^1.4.0 => 1.5.6 
      stylelint-config-taro-rn: 2.0.0-beta.10 => 2.0.0-beta.10 
      stylelint-taro-rn: 2.0.0-beta.10 => 2.0.0-beta.10 

@taro-bot
Copy link

taro-bot bot commented Dec 24, 2019

CC @luckyadam

@taro-bot
Copy link

taro-bot bot commented Dec 24, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@myNameCao
Copy link

你在项目中使用了别名@src 你是否在 在config/index 添加了alias
例如:

const path = require('path');
config={
 alias: {
    '@src': path.resolve(__dirname, '../src')
  },
}

@licanbluesea
Copy link
Author

你在项目中使用了别名@src 你是否在 在config/index 添加了alias
例如:

const path = require('path');
config={
 alias: {
    '@src': path.resolve(__dirname, '../src')
  },
}

已经加了,并不是这个原因

@licanbluesea
Copy link
Author

@myNameCao

@licanbluesea
Copy link
Author

@myNameCao 这个你们应该可以重现的,太明显了

@licanbluesea
Copy link
Author

@myNameCao 或者你们把相应的源码给我调试下,看下是什么原因导致

@licanbluesea
Copy link
Author

licanbluesea commented Dec 24, 2019

@myNameCao 是在mini-runner这一块的吗?我找到组件的适配源码,但是多端方法适配还没有找到,不知道是在那plugin里

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

4 participants