NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.6k stars 4.8k forks source link

初始化项目后,打包bundle报错 #15766

Open 1wayticket opened 5 months ago

1wayticket commented 5 months ago

相关平台

React Native

复现仓库

https://github.com/1wayticket/taro-rn-split.git

使用框架: React

复现步骤

参照教程 使用taro init后,选择分离模式创建工程后,yarn install。配置rn的输出配置,然后执行yarn build:rn --platform android导出bundle,报错如下:

error node_modules/warn-once/index.js: “rootProjectPath”/taro-rn/taro-rn-split/node_modules/warn-once/index.js: Cannot read properties of null (reading 'consequent').
TypeError: “rootProjectPath”/taro-rn/taro-rn-split/node_modules/warn-once/index.js: Cannot read properties of null (reading 'consequent')
    at isRemoved (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:13:29)
    at isRemoved (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:15:10)
    at isRemoved (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:15:10)
    at isRemoved (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:15:10)
    at isRemoved (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:15:10)
    at isRemoved (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:15:10)
    at PluginPass.call (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/helper-define-polyfill-provider/lib/visitors/usage.js:76:104)
    at call (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/visitors.ts:293:14)
    at NodePath._call (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:35:20)
    at NodePath.call (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:20:17)
    at NodePath.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:94:31)
    at TraversalContext.visitQueue (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:147:16)
    at TraversalContext.visitSingle (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:108:19)
    at TraversalContext.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:179:19)
    at traverseNode (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
    at NodePath.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:101:33)
    at TraversalContext.visitQueue (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:147:16)
    at TraversalContext.visitMultiple (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:98:17)
    at TraversalContext.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:177:19)
    at traverseNode (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
    at NodePath.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:101:33)
    at TraversalContext.visitQueue (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:147:16)
    at TraversalContext.visitSingle (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:108:19)
    at TraversalContext.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:179:19)
    at traverseNode (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
    at NodePath.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:101:33)
    at TraversalContext.visitQueue (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:147:16)
    at TraversalContext.visitMultiple (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:98:17)
    at TraversalContext.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:177:19)
    at traverseNode (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
    at NodePath.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/path/context.ts:101:33)
    at TraversalContext.visitQueue (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:147:16)
    at TraversalContext.visitSingle (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:108:19)
    at TraversalContext.visit (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/context.ts:179:19)
    at traverseNode (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/traverse-node.ts:40:17)
    at traverse (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/traverse/src/index.ts:82:15)
    at transformFile (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/core/src/transformation/index.ts:124:15)
    at transformFile.next (<anonymous>)
    at run (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/core/src/transformation/index.ts:48:12)
    at run.next (<anonymous>)
    at “rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/core/src/transform-ast.ts:34:20
    at Generator.next (<anonymous>)
    at evaluateSync (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/gensync/index.js:251:28)
    at fn (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/gensync/index.js:89:14)
    at stopHiding - secret - don't use this - v1 (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/core/src/errors/rewrite-stack-trace.ts:99:14)
    at transformFromAstSync (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@babel/core/src/transform-ast.ts:77:59)
    at Object.transform [as nextTransformer] (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/metro-react-native-babel-transformer/src/index.js:199:20)
    at Object.transform (“rootProjectPath”/taro-rn/taro-rn-split/node_modules/@tarojs/rn-transformer/src/index.ts:44:18)
    at “rootProjectPath”/taro-rn/taro-rn-split/node_modules/@tarojs/rn-supporter/src/taroTransformer.ts:59:51

期望结果

期望正常导出bundle

实际结果

打包报错

环境信息

👽 Taro v3.6.29

  Taro CLI 3.6.29 environment info:
    System:
      OS: macOS 14.4.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
      Yarn: 1.22.22 - ~/.nvm/versions/node/v20.10.0/bin/yarn
      npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.29 => 3.6.29 
      @tarojs/components: 3.6.29 => 3.6.29 
      @tarojs/components-rn: ^3.6.30 => 3.6.30 
      @tarojs/helper: 3.6.29 => 3.6.29 
      @tarojs/plugin-framework-react: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-alipay: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-h5: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-jd: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-qq: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-swan: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-tt: 3.6.29 => 3.6.29 
      @tarojs/plugin-platform-weapp: 3.6.29 => 3.6.29 
      @tarojs/react: 3.6.29 => 3.6.29 
      @tarojs/rn-runner: ^3.6.30 => 3.6.30 
      @tarojs/rn-supporter: ^3.6.30 => 3.6.30 
      @tarojs/runtime: 3.6.29 => 3.6.29 
      @tarojs/runtime-rn: ^3.6.30 => 3.6.30 
      @tarojs/shared: 3.6.29 => 3.6.29 
      @tarojs/taro: 3.6.29 => 3.6.29 
      @tarojs/taro-loader: 3.6.29 => 3.6.29 
      @tarojs/taro-rn: ^3.6.30 => 3.6.30 
      @tarojs/webpack5-runner: 3.6.29 => 3.6.29 
      babel-preset-taro: 3.6.29 => 3.6.29 
      eslint-config-taro: 3.6.29 => 3.6.29 
      expo: ~47.0.3 => 47.0.14 
      react: ^18.1.0 => 18.3.1 
      react-native: ^0.70.5 => 0.70.15 
xwwiiy commented 4 months ago

我也遇到这个问题了,直接taro init新的模板,什么都没做,直接编译就报错了

ahjsrhj commented 3 months ago

同样的问题, yarn dev:rn 可以执行 build就会报错

FxlDeveloper commented 3 months ago

+1 是什么配置不兼容导致的吗?麻烦官方大大给指导一下 不胜感激 { "name": "myApp", "version": "1.0.0", "private": true, "description": "111", "templateInfo": { "name": "default", "typescript": false, "css": "Sass", "framework": "React" }, "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", "build:harmony-hybrid": "taro build --type harmony-hybrid", "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", "dev:harmony-hybrid": "npm run build:harmony-hybrid -- --watch", "test": "jest" }, "browserslist": [ "defaults and fully supports es6-module", "maintained node versions" ], "author": "", "dependencies": { "@babel/runtime": "^7.20.0", "@reduxjs/toolkit": "^1.9.0", "@tarojs/components": "4.0.0-canary.9", "@tarojs/components-rn": "4.0.0-canary.9", "@tarojs/helper": "4.0.0-canary.9", "@tarojs/plugin-framework-react": "4.0.0-canary.9", "@tarojs/plugin-http": "^3.6.24", "@tarojs/plugin-platform-alipay": "4.0.0-canary.9", "@tarojs/plugin-platform-h5": "4.0.0-canary.9", "@tarojs/plugin-platform-harmony-hybrid": "4.0.0-canary.9", "@tarojs/plugin-platform-jd": "4.0.0-canary.9", "@tarojs/plugin-platform-qq": "4.0.0-canary.9", "@tarojs/plugin-platform-swan": "4.0.0-canary.9", "@tarojs/plugin-platform-tt": "4.0.0-canary.9", "@tarojs/plugin-platform-weapp": "4.0.0-canary.9", "@tarojs/react": "4.0.0-canary.9", "@tarojs/redux": "^2.2.10", "@tarojs/rn-runner": "4.0.0-canary.9", "@tarojs/rn-supporter": "4.0.0-canary.9", "@tarojs/runtime": "4.0.0-canary.9", "@tarojs/runtime-rn": "4.0.0-canary.9", "@tarojs/shared": "4.0.0-canary.9", "@tarojs/taro": "4.0.0-canary.9", "@tarojs/taro-rn": "4.0.0-canary.9", "@wuba/react-native-echarts": "^1.3.0", "ali-oss": "^6.20.0", "axios": "^1.6.7", "classnames": "^2.5.1", "crypto-js": "^4.2.0", "dayjs": "^1.11.10", "echarts": "^5.5.0", "expo": "~50.0.2", "js-base64": "^3.7.7", "linear-gradient-taro": "^1.0.1", "md5": "^2.3.0", "prop-types": "^15.8.1", "proptypes": "^1.1.0", "react": "^18.3.1", "react-dom": "^18.3.1", "react-native": "^0.73.1", "react-native-calendars": "^1.1304.1", "react-native-device-info": "^10.13.1", "react-native-gesture-handler": "^2.14.0", "react-native-pager-view": "~6.0.1", "react-native-qrcode-svg": "^6.3.0", "react-native-splash-screen": "^3.3.0", "react-native-svg": "~14.1.0", "react-native-view-shot": "^3.8.0", "react-redux": "^9.1.0", "redux-persist": "^6.0.0", "taro-code": "^4.0.1", "taro-react-echarts": "^1.2.2", "taro-ui": "^3.3.0" }, "devDependencies": { "@babel/core": "^7.24.9", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", "@tarojs/cli": "4.0.0-canary.9", "@tarojs/taro-loader": "4.0.0-canary.9", "@tarojs/test-utils-react": "^0.1.1", "@tarojs/webpack5-runner": "4.0.0-canary.9", "@types/jest": "^29.3.1", "@types/node": "^18.15.11", "@types/webpack-env": "^1.13.6", "ahooks": "^3.7.10", "babel-preset-taro": "4.0.0-canary.9", "eslint": "^8.12.0", "eslint-config-prettier": "^9.1.0", "eslint-config-taro": "4.0.0-canary.9", "eslint-import-resolver-alias": "^1.1.2", "eslint-plugin-import": "^2.12.0", "eslint-plugin-react": "^7.8.2", "eslint-plugin-react-hooks": "^4.2.0", "jest": "^29.3.1", "jest-environment-jsdom": "^29.5.0", "postcss": "^8.4.18", "prettier": "^2.8.8", "react-refresh": "^0.11.0", "stylelint": "^14.4.0", "taro-iconfont-cli": "^3.3.0", "ts-node": "^10.9.1", "webpack": "5.78.0", "webpack-bundle-analyzer": "^4.10.1", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/eslint-config": "^0.73.1", "@react-native/metro-config": "^0.73.2", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "install-peerdeps": "^3.0.3", "pod-install": "^0.1.38", "react-test-renderer": "18.2.0", "typescript": "5.0.4" } }

ahjsrhj commented 3 months ago

+1 是什么配置不兼容导致的吗?麻烦官方大大给指导一下 不胜感激 { "name": "myApp", "version": "1.0.0", "private": true, "description": "111", "templateInfo": { "name": "default", "typescript": false, "css": "Sass", "framework": "React" }, "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", "build:harmony-hybrid": "taro build --type harmony-hybrid", "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", "dev:harmony-hybrid": "npm run build:harmony-hybrid -- --watch", "test": "jest" }, "browserslist": [ "defaults and fully supports es6-module", "maintained node versions" ], "author": "", "dependencies": { "@babel/runtime": "^7.20.0", "@reduxjs/toolkit": "^1.9.0", "@tarojs/components": "4.0.0-canary.9", "@tarojs/components-rn": "4.0.0-canary.9", "@tarojs/helper": "4.0.0-canary.9", "@tarojs/plugin-framework-react": "4.0.0-canary.9", "@tarojs/plugin-http": "^3.6.24", "@tarojs/plugin-platform-alipay": "4.0.0-canary.9", "@tarojs/plugin-platform-h5": "4.0.0-canary.9", "@tarojs/plugin-platform-harmony-hybrid": "4.0.0-canary.9", "@tarojs/plugin-platform-jd": "4.0.0-canary.9", "@tarojs/plugin-platform-qq": "4.0.0-canary.9", "@tarojs/plugin-platform-swan": "4.0.0-canary.9", "@tarojs/plugin-platform-tt": "4.0.0-canary.9", "@tarojs/plugin-platform-weapp": "4.0.0-canary.9", "@tarojs/react": "4.0.0-canary.9", "@tarojs/redux": "^2.2.10", "@tarojs/rn-runner": "4.0.0-canary.9", "@tarojs/rn-supporter": "4.0.0-canary.9", "@tarojs/runtime": "4.0.0-canary.9", "@tarojs/runtime-rn": "4.0.0-canary.9", "@tarojs/shared": "4.0.0-canary.9", "@tarojs/taro": "4.0.0-canary.9", "@tarojs/taro-rn": "4.0.0-canary.9", "@wuba/react-native-echarts": "^1.3.0", "ali-oss": "^6.20.0", "axios": "^1.6.7", "classnames": "^2.5.1", "crypto-js": "^4.2.0", "dayjs": "^1.11.10", "echarts": "^5.5.0", "expo": "~50.0.2", "js-base64": "^3.7.7", "linear-gradient-taro": "^1.0.1", "md5": "^2.3.0", "prop-types": "^15.8.1", "proptypes": "^1.1.0", "react": "^18.3.1", "react-dom": "^18.3.1", "react-native": "^0.73.1", "react-native-calendars": "^1.1304.1", "react-native-device-info": "^10.13.1", "react-native-gesture-handler": "^2.14.0", "react-native-pager-view": "~6.0.1", "react-native-qrcode-svg": "^6.3.0", "react-native-splash-screen": "^3.3.0", "react-native-svg": "~14.1.0", "react-native-view-shot": "^3.8.0", "react-redux": "^9.1.0", "redux-persist": "^6.0.0", "taro-code": "^4.0.1", "taro-react-echarts": "^1.2.2", "taro-ui": "^3.3.0" }, "devDependencies": { "@babel/core": "^7.24.9", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", "@tarojs/cli": "4.0.0-canary.9", "@tarojs/taro-loader": "4.0.0-canary.9", "@tarojs/test-utils-react": "^0.1.1", "@tarojs/webpack5-runner": "4.0.0-canary.9", "@types/jest": "^29.3.1", "@types/node": "^18.15.11", "@types/webpack-env": "^1.13.6", "ahooks": "^3.7.10", "babel-preset-taro": "4.0.0-canary.9", "eslint": "^8.12.0", "eslint-config-prettier": "^9.1.0", "eslint-config-taro": "4.0.0-canary.9", "eslint-import-resolver-alias": "^1.1.2", "eslint-plugin-import": "^2.12.0", "eslint-plugin-react": "^7.8.2", "eslint-plugin-react-hooks": "^4.2.0", "jest": "^29.3.1", "jest-environment-jsdom": "^29.5.0", "postcss": "^8.4.18", "prettier": "^2.8.8", "react-refresh": "^0.11.0", "stylelint": "^14.4.0", "taro-iconfont-cli": "^3.3.0", "ts-node": "^10.9.1", "webpack": "5.78.0", "webpack-bundle-analyzer": "^4.10.1", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/eslint-config": "^0.73.1", "@react-native/metro-config": "^0.73.2", "@types/react": "^18.2.6", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.6.3", "install-peerdeps": "^3.0.3", "pod-install": "^0.1.38", "react-test-renderer": "18.2.0", "typescript": "5.0.4" } }

版本用4.0.2试试

xiaobc1234 commented 3 months ago

遇到同样的错误,有解决方法吗?

qnnp-me commented 3 months ago

同问题~

hisanshao commented 2 months ago

config/index.ts设置{env: { NODE_ENV: JSON.stringify(process.env.NODE_ENV) }} 可以解决 原因是warn-once这个包使用了const DEV = process.env.NODE_ENV !== "production";