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

编译不过 #35

Closed
gooddaddy opened this issue Sep 13, 2022 · 15 comments
Closed

编译不过 #35

gooddaddy opened this issue Sep 13, 2022 · 15 comments
Labels
bug Something isn't working need reproduce not provide code split or repo question Further information is requested taro-hooks-next next version own

Comments

@gooddaddy
Copy link

gooddaddy commented Sep 13, 2022

Question

微信小程 编译不过 (taro react 环境)
版本:2.0.0-beta-serro.3

Sample Code

./node_modules/@taro-hooks/shared/dist/shared.esm.js 12:20
Module parse failed: Unexpected token (12:20)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| ENV_TYPE["JD"] = "JD";
| })(ENV_TYPE || (ENV_TYPE = {}));

const ENV = process?.env?.TARO_ENV;
| const ISWEAPP = ENV === ENV_TYPE.WEAPP;
| const ISWEB = ENV === ENV_TYPE.WEB;

@gooddaddy gooddaddy added the question Further information is requested label Sep 13, 2022
@github-actions github-actions bot added the need reproduce not provide code split or repo label Sep 13, 2022
@innocces innocces added need reproduce not provide code split or repo and removed need reproduce not provide code split or repo labels Sep 13, 2022
@github-actions
Copy link

Hello @gooddaddy. In order to facilitate location and troubleshooting, we need you to provide a realistic example. You can create a taro project by clicking here and provide the GitHub warehouse address and reproduce examples.

你好 @gooddaddy, 为了方便定位和排查问题,我们需要你提供一个重现实例。你可以通过点击 此处 创建一个 Taro 项目并提供 GitHub 仓库地址和重现实例。

@gooddaddy
Copy link
Author

gooddaddy commented Sep 14, 2022

Hello @gooddaddy. In order to facilitate location and troubleshooting, we need you to provide a realistic example. You can create a taro project by clicking here and provide the GitHub warehouse address and reproduce examples.

你好 @gooddaddy, 为了方便定位和排查问题,我们需要你提供一个重现实例。你可以通过点击 此处 创建一个 Taro 项目并提供 GitHub 仓库地址和重现实例。

一.编译过了,但是目前类型有问题;
declare function useRequest<TData, TParams extends any[]>(service: Service<TData, TParams>, options?: Options<TData, TParams>, plugins?: Plugin<TData, TParams>[]): import("./types").Result<TData, TParams> | undefined;

为啥useRequest 返回值可能是 undefined 的?这样会导致 调用useRequest后不能直接解构。

二.运行时 报错

.._src_runtime_connect.ts:275 TypeError: Object(...) is not a function
at useLatest (.node_modules@taro-hooks_ahooks_es_useLatest_index.js:4)
at useRequestImplement (.node_modules@taro-hooks_use-request_es_useRequestImplement.js:30)
at useRequest (.node_modules@taro-hooks_use-request_es_useRequest.js:12)
at ._src_pages_home_index.tsx:54
at .._src_observer.ts:104
at .._src_useObserver.ts:115
at trackDerivedFunction (.._src_core_derivation.ts:183)
at Reaction.track (.._src_core_reaction.ts:137)
at useObserver (.._src_useObserver.ts:113)
at observerComponent (.._src_observer.ts:104)(env: macOS,mp,1.06.2208010; lib: 2.25.1)
找到对应的源码 发现:
image

@innocces
Copy link
Owner

Hello @gooddaddy. In order to facilitate location and troubleshooting, we need you to provide a realistic example. You can create a taro project by clicking here and provide the GitHub warehouse address and reproduce examples.
你好 @gooddaddy, 为了方便定位和排查问题,我们需要你提供一个重现实例。你可以通过点击 此处 创建一个 Taro 项目并提供 GitHub 仓库地址和重现实例。

一.编译过了,但是目前类型有问题; declare function useRequest<TData, TParams extends any[]>(service: Service<TData, TParams>, options?: Options<TData, TParams>, plugins?: Plugin<TData, TParams>[]): import("./types").Result<TData, TParams> | undefined;

为啥useRequest 返回值可能是 undefined 的?这样会导致 调用useRequest后不能直接解构。

二.运行时 报错

.._src_runtime_connect.ts:275 TypeError: Object(...) is not a function at useLatest (.node_modules@taro-hooks_ahooks_es_useLatest_index.js:4) at useRequestImplement (.node_modules@taro-hooks_use-request_es_useRequestImplement.js:30) at useRequest (.node_modules@taro-hooks_use-request_es_useRequest.js:12) at ._src_pages_home_index.tsx:54 at .._src_observer.ts:104 at .._src_useObserver.ts:115 at trackDerivedFunction (.._src_core_derivation.ts:183) at Reaction.track (.._src_core_reaction.ts:137) at useObserver (.._src_useObserver.ts:113) at observerComponent (.._src_observer.ts:104)(env: macOS,mp,1.06.2208010; lib: 2.25.1) 找到对应的源码 发现: image

  1. 若请求发生失败或者出错的过程。data可能是为空的. 并且初始是data也是undefined
  2. 运行时报错可以参考一下框架配置。看下是不是有配置没有引入。配置

@innocces innocces added the taro-hooks-next next version own label Sep 14, 2022
@gooddaddy
Copy link
Author

gooddaddy commented Sep 14, 2022

若请求发生失败或者出错的过程。data可能是为空的. 并且初始是data也是undefined
data 为空正常,但是 你这里是 函数 返回都是是空,ahooks 里面的 useRequest 返回类型都不是这样的,你是不是写错了?

@innocces
Copy link
Owner

若请求发生失败或者出错的过程。data可能是为空的. 并且初始是data也是undefined
data 为空正常,但是 你这里是 函数 返回都是是空,ahooks 里面的 useRequest 返回类型都不是这样的,你是不是写错了?

是一样的 Tdata

@gooddaddy
Copy link
Author

若请求发生失败或者出错的过程。data可能是为空的. 并且初始是data也是undefined
data 为空正常,但是 你这里是 函数 返回都是是空,ahooks 里面的 useRequest 返回类型都不是这样的,你是不是写错了?

是一样的 Tdata

这是 ahooks的类型声明:

import type { Options, Plugin, Service } from './types';
declare function useRequest<TData, TParams extends any[]>(service: Service<TData, TParams>, options?: Options<TData, TParams>, plugins?: Plugin<TData, TParams>[]): import("./types").Result<TData, TParams>;
export default useRequest;

这是你的声明:

import type { Options, Plugin, Service } from './types';
declare function useRequest<TData, TParams extends any[]>(service: Service<TData, TParams>, options?: Options<TData, TParams>, plugins?: Plugin<TData, TParams>[]): import("./types").Result<TData, TParams> | undefined;
export default useRequest;

你的在后面 | undefined

@innocces
Copy link
Owner

额。可能是编译的锅。这个我得看看

@innocces innocces added the bug Something isn't working label Sep 14, 2022
@gooddaddy
Copy link
Author

额。可能是编译的锅。这个我得看看

帮忙看看,另外一个问题,我用taro cli 创建一个最新的工程,然后按照你的方式配置,工程能编译通过,但是运行报错(目前最新的taro 是3.5.5 工程默认是 webpack5的,你的插件是不是 不支持webpack5?)

@innocces
Copy link
Owner

额。可能是编译的锅。这个我得看看

帮忙看看,另外一个问题,我用taro cli 创建一个最新的工程,然后按照你的方式配置,工程能编译通过,但是运行报错(目前最新的taro 是3.5.5 工程默认是 webpack5的,你的插件是不是 不支持webpack5?)

空的项目么?

@gooddaddy
Copy link
Author

额。可能是编译的锅。这个我得看看

帮忙看看,另外一个问题,我用taro cli 创建一个最新的工程,然后按照你的方式配置,工程能编译通过,但是运行报错(目前最新的taro 是3.5.5 工程默认是 webpack5的,你的插件是不是 不支持webpack5?)

空的项目么?
工程向导中选择:react 、typescript 、webpack5 创建工程

@innocces
Copy link
Owner

node 版本可以提供一下么

@gooddaddy
Copy link
Author

node 版本可以提供一下么

node 8.5.0

package.json

{
  "name": "myApp",
  "version": "1.0.0",
  "private": true,
  "description": "",
  "templateInfo": {
    "name": "default",
    "typescript": true,
    "css": "sass"
  },
  "scripts": {
    "build:weapp": "taro build --type weapp",
    "build:swan": "taro build --type swan",
    "build:alipay": "taro build --type alipay",
    "build:tt": "taro build --type tt",
    "build:h5": "taro build --type h5",
    "build:rn": "taro build --type rn",
    "build:qq": "taro build --type qq",
    "build:jd": "taro build --type jd",
    "build:quickapp": "taro build --type quickapp",
    "dev:weapp": "npm run build:weapp -- --watch",
    "dev:swan": "npm run build:swan -- --watch",
    "dev:alipay": "npm run build:alipay -- --watch",
    "dev:tt": "npm run build:tt -- --watch",
    "dev:h5": "npm run build:h5 -- --watch",
    "dev:rn": "npm run build:rn -- --watch",
    "dev:qq": "npm run build:qq -- --watch",
    "dev:jd": "npm run build:jd -- --watch",
    "dev:quickapp": "npm run build:quickapp -- --watch"
  },
  "browserslist": [
    "last 3 versions",
    "Android >= 4.1",
    "ios >= 8"
  ],
  "author": "",
  "dependencies": {
    "@babel/runtime": "^7.7.7",
    "@tarojs/components": "3.5.5",
    "@tarojs/helper": "3.5.5",
    "@tarojs/mini-runner": "^3.5.5",
    "@tarojs/plugin-framework-react": "3.5.5",
    "@tarojs/plugin-platform-alipay": "3.5.5",
    "@tarojs/plugin-platform-jd": "3.5.5",
    "@tarojs/plugin-platform-qq": "3.5.5",
    "@tarojs/plugin-platform-swan": "3.5.5",
    "@tarojs/plugin-platform-tt": "3.5.5",
    "@tarojs/plugin-platform-weapp": "3.5.5",
    "@tarojs/react": "3.5.5",
    "@tarojs/router": "3.5.5",
    "@tarojs/runtime": "3.5.5",
    "@tarojs/shared": "3.5.5",
    "@tarojs/taro": "3.5.5",
    "@tarojs/taro-h5": "3.5.5",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "taro-hooks": "^2.0.0-beta-serro.3"
  },
  "devDependencies": {
    "@babel/core": "^7.8.0",
    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
    "@taro-hooks/plugin-react": "^2.0.0-beta-serro.3",
    "@tarojs/cli": "3.5.5",
    "@tarojs/webpack5-runner": "3.5.5",
    "@types/react": "^18.0.0",
    "@types/webpack-env": "^1.13.6",
    "@typescript-eslint/eslint-plugin": "^5.20.0",
    "@typescript-eslint/parser": "^5.20.0",
    "babel-preset-taro": "3.5.5",
    "eslint": "^8.12.0",
    "eslint-config-taro": "3.5.5",
    "eslint-plugin-import": "^2.12.0",
    "eslint-plugin-react": "^7.8.2",
    "eslint-plugin-react-hooks": "^4.2.0",
    "react-refresh": "^0.11.0",
    "stylelint": "^14.4.0",
    "typescript": "^4.1.0",
    "webpack": "5.69.0"
  }
}

@innocces
Copy link
Owner

暂时定位到的问题是:

  1. webpack5 模式下会开启预编译. 导致runtime失效. 需要关闭预编译
 compiler: {
    type: 'webpack5',
    // 依赖预编译配置
    prebundle: {
      enable: false
    }
 },
  1. 3.5 开始貌似不再开发process变量了. 但是shared会依赖这个. (这个有待解决)

  2. 模板忘记加 babel-plugin-import 这个依赖了。

模板的问题后面会一起解决. 包的问题需要再看下解决方案. 如果着急可以用 3.5 以下的版本

@innocces
Copy link
Owner

记录一下相关issue

NervJS/taro#12385

@innocces
Copy link
Owner

process 的 问题可以通过安装最新版来解决, taro-hooks-v2.0.0-beta-serro.5

官方模板这边快尽快更新.

以上. 若有问题再重新open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need reproduce not provide code split or repo question Further information is requested taro-hooks-next next version own
Projects
None yet
Development

No branches or pull requests

2 participants