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 3.0.2 同一个页面如果是默认页则没问题,但是如果是内页则微信调试工具报错误:Taro is not defined #6924

Closed
puxiao opened this issue Jul 6, 2020 · 2 comments

Comments

@puxiao
Copy link

puxiao commented Jul 6, 2020

相关平台

微信小程序

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

复现步骤

import React from 'react'
import Taro from '@tarojs/taro'
import { View, Button} from '@tarojs/components'
const MoodmapPage: React.FC<{}> = () => {

    const handleGetLocation = () => {
        Taro.getLocation({
            type:'gcj02',
            success:(res) => {
                console.log(res)
            }
        })
    }

    return (
        <View>
            <Button onClick={handleGetLocation} type='primary' >获取位置</Button>
        </View>
    )
}

export default MoodmapPage

以上为我在 Trao 中创建的一个页面,其中使用到了 Taro.getLocation 函数。
当我在 app.config.ts pages 中,把这个页面设置为 小程序默认页,Taro 编译正常,微信调试工具运行正常。
但是如果我把 这个页面 当做内页,小程序默认页上放置按钮(默认页并未使用或引入 Taro),点击按钮通过 Taro.navigateTo 跳转到该页面时,Taro 编译正常,但微信调试工具报错:

MiniProgramError
Taro is not defined
ReferenceError: Taro is not defined
    at n.e (http://127.0.0.1:47466/appservice/pages/welcome/index.js:1:1252)
    at n.value (http://127.0.0.1:47466/appservice/taro.js:1:40890)
    at Ge.We [as eh] (http://127.0.0.1:47466/appservice/taro.js:1:15739)
    at Object.r.safeCallback (http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:1775461)
    at http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:1911602
    at s (http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:1922566)
    at http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:1911527
    at r (http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:1852726)
    at http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:1852848
    at http://127.0.0.1:47466/appservice/__dev__/WAService.js:2:919306

期望结果

无论该页面是否为首页还是内页,都应该运行正常。

实际结果

该页面只有被设定为默认页时,才运行正常。如果被设定为 内页,则报错误:ReferenceError: Taro is not defined

环境信息

 Taro v3.0.2


  Taro CLI 3.0.2 environment info:
    System:
      OS: Windows 7
    Binaries:
      Node: 12.13.0 - D:\Program Files\nodejs\node.EXE
      npm: 6.14.2 - D:\Program Files\nodejs\npm.CMD

补充信息

默认页如果未使用Taro,没有 import Taro from '@tarojs/taro',那么 内页如果用到了 Taro 且顶部写有 import,但是 Taro 依然未被编译进去?

@liyanging
Copy link

我也遇到相同的问题,在txs文件里面使用Taro.setStorage 没问题,如果把这个封装成一个文件,再调用Taro.setStorage 就报Taro is not defined。

@puxiao
Copy link
Author

puxiao commented May 7, 2022

额~ 陈年老 issues 了,我自己都忘了。

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

2 participants