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 v3.5.6】将页面配置赋值给变量,然后导出,编译会报错 #12674

Closed
qiuxiyu opened this issue Oct 18, 2022 · 18 comments · Fixed by #12785
Closed

【Taro v3.5.6】将页面配置赋值给变量,然后导出,编译会报错 #12674

qiuxiyu opened this issue Oct 18, 2022 · 18 comments · Fixed by #12785
Assignees
Labels
F-react Framework - React P-1 High, patch T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Milestone

Comments

@qiuxiyu
Copy link

qiuxiyu commented Oct 18, 2022

相关平台

微信小程序

复现仓库

https://github.com/qiuxiyu/taro_issue_demo/blob/main/myApp.zip
小程序基础库: 2.11.2
使用框架: React
使用 Taro cli 版本:3.5.6

复现步骤

0. 安装 3.5.6 版本的 Taro cli

1. 执行命令行,初始化项目:

taro init myApp

2. 修改 myApp/src/pages/index/index.config.js 的内容:

------------ before ------------

export default {
  navigationBarTitleText: '首页',
  usingComponents: {
  }
}

------------ after ------------

const config = {
  navigationBarTitleText: '首页',
  usingComponents: {
  }
}

export default config

3. 执行命令行,编译项目:

npm run build:weapp 

期望结果

编译成功且运行正常,不要报错

实际结果

编译报错,错误信息为:

node_modules/@swc/core/index.js:241
          return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
                          ^


Error: failed to handle: index out of bounds: the len is 1 but the index is 1
    at Compiler.transformSync (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/@swc/core/index.js:241:27)
    at Compiler.transformSync (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/@swc/core/index.js:239:29)
    at Object.transformSync (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/@swc/core/index.js:349:21)
    at compile (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/@swc/register/lib/node.js:76:22)
    at compileHook (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/@swc/register/lib/node.js:91:16)
    at Module._compile (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/pirates/lib/index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Object.newLoader [as .js] (/Users/bianyl/workespace/fastapp/taro/taro35/.minicache/tarobaseproject/node_modules/pirates/lib/index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'GenericFailure'
}

环境信息

👽 Taro v3.5.6


  Taro CLI 3.5.6 environment info:
    System:
      OS: macOS 11.6
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Oct 18, 2022
@Chen-jj Chen-jj self-assigned this Oct 18, 2022
@Chen-jj Chen-jj added the P-1 High, patch label Oct 18, 2022
@taro-bot2 taro-bot2 bot modified the milestone: 3.5.7 Oct 18, 2022
@Chen-jj Chen-jj modified the milestones: 3.5.7, 3.5.8 Oct 18, 2022
@yoyo837
Copy link
Contributor

yoyo837 commented Oct 20, 2022

该不会把js文件内容按export defualt模版字符串解析的吧? 😳

@SpringHgui
Copy link
Contributor

使用cli将项目从 3.4.4 升级 3.5.7 升级成功后编译,遇到同样问题

PS D:\Gitlab\taro-market> npm run dev:tgj:weapp

> taro-market@1.0.0 dev:tgj:weapp
> cross-env APP_ENV=tgj npm run build:weapp -- --watch


> taro-market@1.0.0 build:weapp
> taro build --type weapp "--watch"

👽 Taro v3.5.7

Tips:
1. 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
$ set NODE_ENV=production && taro build --type weapp --watch



thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\swc_common-0.29.10\src\syntax_pos\hygiene.rs:580:34note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failed to handle: index out of bounds: the len is 1 but the index is 1


failed to handle: index out of bounds: the len is 1 but the index is 1


node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: failed to handle: index out of bounds: the len is 1 but the index is 1
    at Compiler.transformSync (D:\Gitlab\taro-market\node_modules\@swc\core\index.js:241:29)
    at Compiler.transformSync (D:\Gitlab\taro-market\node_modules\@swc\core\index.js:239:29)
    at Object.transformSync (D:\Gitlab\taro-market\node_modules\@swc\core\index.js:348:21)
    at compile (D:\Gitlab\taro-market\node_modules\@swc\register\lib\node.js:76:22)
    at compileHook (D:\Gitlab\taro-market\node_modules\@swc\register\lib\node.js:91:16)
    at Module._compile (D:\Gitlab\taro-market\node_modules\pirates\lib\index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at newLoader (C:\Users\Sprin\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\pirates\lib\index.js:141:7)
    at Object.newLoader [as .js] (D:\Gitlab\taro-market\node_modules\pirates\lib\index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at readConfig (D:\Gitlab\taro-market\node_modules\@tarojs\helper\src\utils.ts:659:37)
    at TaroMiniPlugin.compileFile (D:\Gitlab\taro-market\node_modules\@tarojs\mini-runner\src\plugins\MiniPlugin.ts:669:34)
    at TaroMiniPlugin.getAppConfig (D:\Gitlab\taro-market\node_modules\@tarojs\mini-runner\src\plugins\MiniPlugin.ts:519:10) {
  code: 'GenericFailure'
}
PS D:\Gitlab\taro-market>

@SpringHgui
Copy link
Contributor

确实奇怪,我新建全新项目,修改app.config.js,同样的报错

// app.config.js
const config = {
  pages: ["pages/index/index"],
  window: {
    backgroundTextStyle: "light",
    navigationBarBackgroundColor: "#fff",
    navigationBarTitleText: "WeChat",
    navigationBarTextStyle: "black",
  },
};

export default config;
PS D:\demo\myapp> npm run dev:weapp

> myapp@1.0.0 dev:weapp
> npm run build:weapp -- --watch


> myapp@1.0.0 build:weapp
> taro build --type weapp "--watch"

👽 Taro v3.5.7

Tips:
1. 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
$ set NODE_ENV=production && taro build --type weapp --watch
2. 建议开启持久化缓存功能,能有效提升二次编译速度,详情请参考: https://docs.taro.zone/docs/config-detail#cache。


thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\swc_common-0.29.10\src\syntax_pos\hygiene.rs:580:34note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
D:\demo\myapp\node_modules\@swc\core\index.js:241
            return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
                            ^

Error: failed to handle: index out of bounds: the len is 1 but the index is 1
    at Compiler.transformSync (D:\demo\myapp\node_modules\@swc\core\index.js:241:29)
    at Compiler.transformSync (D:\demo\myapp\node_modules\@swc\core\index.js:239:29)
    at Object.transformSync (D:\demo\myapp\node_modules\@swc\core\index.js:348:21)
    at compile (D:\demo\myapp\node_modules\@swc\register\lib\node.js:76:22)
    at compileHook (D:\demo\myapp\node_modules\@swc\register\lib\node.js:91:16)
    at Module._compile (D:\demo\myapp\node_modules\pirates\lib\index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.newLoader [as .js] (D:\demo\myapp\node_modules\pirates\lib\index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'GenericFailure'
}

@Elliott-Hu
Copy link

@tarojs/helper 包的 createSwcRegister 方法并不能完全替代 createBabelRegister,我看缺挺多plugins 的。

@Elliott-Hu
Copy link

需要先调用 createBabelRegister 方法提前对 app.config.ts 文件进行一遍编译。再执行 readConfig() 获取appConfig就可以。不过我不太清楚为什么要 delete require.cache ,这一步的目的是啥?
image

@dduuxxuu
Copy link

dduuxxuu commented Nov 3, 2022

遇到了同样问题

@Chen-jj
Copy link
Contributor

Chen-jj commented Nov 3, 2022

问题出在以 JS 编写的 swc 自定义插件上。

目前可以用 resolution 配置项去锁 @swc/core 的版本:swc-project/swc#6255

@Chen-jj
Copy link
Contributor

Chen-jj commented Nov 3, 2022

@tarojs/helper 包的 createSwcRegister 方法并不能完全替代 createBabelRegister,我看缺挺多plugins 的。

@Elliott-Hu swc 把 babel 的插件都撸了遍(以内置实现+选项开启的方式),挺全的了:https://swc.rs/docs/migrating-from-babel

@babel/register@swc/register 一样,require 文件时对其进行编译,而 require 有 cache,所以要清除,否则不会刷新。

@dduuxxuu
Copy link

dduuxxuu commented Nov 3, 2022

"resolutions": { "@swc/core": "1.3.6" }
可以解决

@Chen-jj
Copy link
Contributor

Chen-jj commented Nov 7, 2022

Taro v3.5.8 将使用 rust 插件代替 js 插件,可以绕过此问题。

@ZakaryCode ZakaryCode modified the milestones: 3.5.8, 3.5.9 Nov 29, 2022
@songwenhui
Copy link

Taro v3.5.8 将使用 rust 插件代替 js 插件,可以绕过此问题。

已升级 3.5.8,仍然报该错,入口config文件直接使用json没有问题,js动态生成config就会报错

@SpringHgui
Copy link
Contributor

SpringHgui commented Dec 7, 2022

Taro v3.5.8 将使用 rust 插件代替 js 插件,可以绕过此问题。

已升级3.5.8,仍然存在这个问题

PS D:\Gitlab\taro.market> npm run dev:yz:weapp  

> taro-market@1.0.0 dev:yz:weapp
> cross-env APP_ENV=yz npm run build:weapp -- --watch


> taro-market@1.0.0 build:weapp
> taro build --type weapp "--watch"

👽 Taro v3.5.8

Tips:
1. 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
$ set NODE_ENV=production && taro build --type weapp --watch



thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\swc_common-0.29.16\src\syntax_pos\hygiene.rs:580:34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failed to handle: index out of bounds: the len is 1 but the index is 1


failed to handle: index out of bounds: the len is 1 but the index is 1


node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: failed to handle: index out of bounds: the len is 1 but the index is 1
    at Compiler.transformSync (D:\Gitlab\taro.market\node_modules\@swc\core\index.js:241:29)
    at Compiler.transformSync (D:\Gitlab\taro.market\node_modules\@swc\core\index.js:239:29)
    at Object.transformSync (D:\Gitlab\taro.market\node_modules\@swc\core\index.js:348:21)
    at compile (D:\Gitlab\taro.market\node_modules\@swc\register\lib\node.js:76:22)
    at compileHook (D:\Gitlab\taro.market\node_modules\@swc\register\lib\node.js:91:16)
    at Module._compile (D:\Gitlab\taro.market\node_modules\pirates\lib\index.js:130:29)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at newLoader (C:\Users\Sprin\AppData\Roaming\npm\node_modules\@tarojs\cli\node_modules\pirates\lib\index.js:141:7)
    at Object.newLoader [as .js] (D:\Gitlab\taro.market\node_modules\pirates\lib\index.js:141:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at readConfig (D:\Gitlab\taro.market\node_modules\@tarojs\helper\src\utils.ts:659:37)
    at TaroMiniPlugin.compileFile (D:\Gitlab\taro.market\node_modules\@tarojs\mini-runner\src\plugins\MiniPlugin.ts:669:34)
    at TaroMiniPlugin.getAppConfig (D:\Gitlab\taro.market\node_modules\@tarojs\mini-runner\src\plugins\MiniPlugin.ts:519:10) {
  code: 'GenericFailure'
}
PS D:\Gitlab\taro.market>

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 7, 2022

还没发布的,这周 3.5.9 带出去

@songwenhui
Copy link

3.5.9版本还是会报这个错

thread '' panicked at 'index out of bounds: the len is 1 but the index is 1', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/swc_common-0.29.16/src/syntax_pos/hygiene.rs:580:34
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: failed to handle: index out of bounds: the len is 1 but the index is 1

@Tecode
Copy link

Tecode commented Dec 9, 2022

3.5.9会报这个错误,系统是centos6

+ /usr/local/bin/yarn build:test:weapp
yarn run v1.22.19
$ cross-env NODE_ENV=TEST taro build --type weapp
👽 Taro v3.5.9

thread '<unnamed>' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:552:70
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
error Command failed with exit code 1.

@zhouzyc
Copy link

zhouzyc commented Dec 27, 2022

3.5.9会报这个错误,系统是centos6

+ /usr/local/bin/yarn build:test:weapp
yarn run v1.22.19
$ cross-env NODE_ENV=TEST taro build --type weapp
👽 Taro v3.5.9

thread '<unnamed>' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:552:70
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
error Command failed with exit code 1.

请问解决了吗,遇到一样问题

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 27, 2022

3.5.9会报这个错误,系统是centos6

+ /usr/local/bin/yarn build:test:weapp
yarn run v1.22.19
$ cross-env NODE_ENV=TEST taro build --type weapp
👽 Taro v3.5.9

thread '<unnamed>' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:552:70
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
error Command failed with exit code 1.

3.5.9 遗漏了这个特性,需要 3.5.10~

@zhouzyc
Copy link

zhouzyc commented Dec 27, 2022

3.5.9会报这个错误,系统是centos6

+ /usr/local/bin/yarn build:test:weapp
yarn run v1.22.19
$ cross-env NODE_ENV=TEST taro build --type weapp
👽 Taro v3.5.9

thread '<unnamed>' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:552:70
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
error Command failed with exit code 1.

3.5.9 遗漏了这个特性,需要 3.5.10~

我3.5.10 一样的

qiuxiyu added a commit to qiuxiyu/taro_issue_demo that referenced this issue Feb 3, 2023
【Taro v3.5.6】将页面配置赋值给变量,然后导出,编译会报错 #12674
NervJS/taro#12674
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React P-1 High, patch T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants