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

多端组件 编译报错:Cannot read property 'content' of undefined #8652

Closed
mrzzcn opened this issue Feb 5, 2021 · 3 comments
Closed
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@mrzzcn
Copy link

mrzzcn commented Feb 5, 2021

相关平台

微信小程序

复现仓库

https://gitee.com/mrzzcn/hello-tarojs
小程序基础库: 1
使用框架: React

复现步骤

taro init hello-tarojs

cp app.config.ts app.config.weapp.ts

yarn dev:weapp

期望结果

正常编译

实际结果

报错

yarn run v1.22.10
$ npm run build:weapp -- --watch

hello-tarojs@1.0.0 build:weapp
taro build --type weapp "--watch"

👽 Taro v3.0.26

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Tips: 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
Example:
$ NODE_ENV=production taro build --type weapp --watch

生成 工具配置 /Users/z/dev/hello-tarojs/dist/project.config.json

编译 发现入口 src/app.ts
编译 发现页面 src/pages/index/index.tsx
⠏ 正在编译...Cannot read property 'content' of undefined

Cannot read property 'content' of undefined

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

TypeError: Cannot read property 'content' of undefined
at TaroMiniPlugin. (/Users/z/dev/hello-tarojs/node_modules/@tarojs/mini-runner/src/plugins/MiniPlugin.ts:649:91)
at Generator.next ()
at fulfilled (/Users/z/dev/hello-tarojs/node_modules/@tarojs/mini-runner/dist/plugins/MiniPlugin.js:5:58)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:93:5)
npm ERR! code 1
npm ERR! path /Users/z/dev/hello-tarojs
npm ERR! command failed
npm ERR! command sh -c taro build --type weapp "--watch"

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/z/.npm/_logs/2021-02-05T03_36_22_208Z-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

环境信息

👽 Taro v3.0.26


  Taro CLI 3.0.26 environment info:
    System:
      OS: macOS 11.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 15.4.0 - /usr/local/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 7.0.15 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.0.26 => 3.0.26 
      @tarojs/mini-runner: 3.0.26 => 3.0.26 
      @tarojs/react: 3.0.26 => 3.0.26 
      @tarojs/runtime: 3.0.26 => 3.0.26 
      @tarojs/taro: 3.0.26 => 3.0.26 
      @tarojs/webpack-runner: 3.0.26 => 3.0.26 
      babel-preset-taro: 3.0.26 => 3.0.26 
      eslint-config-taro: 3.0.26 => 3.0.26 
      react: ^16.10.0 => 16.14.0 
    npmGlobalPackages:
      typescript: 3.7.2



补充信息

此处:https://github.com/NervJS/taro/blob/next/packages/taro-mini-runner/src/plugins/MiniPlugin.ts#L535

    this.filesConfig[this.getConfigFilePath(file.name)] = {
      content: fileConfig,
      path: fileConfigPath
    }

和此处:https://github.com/NervJS/taro/blob/next/packages/taro-mini-runner/src/plugins/MiniPlugin.ts#L647

    const appConfigPath = this.getConfigFilePath(this.appEntry)
    const appConfigName = path.basename(appConfigPath).replace(path.extname(appConfigPath), '')
    if (!this.options.blended) {
      this.generateConfigFile(compilation, this.appEntry, this.filesConfig[appConfigName].content)
    }

计算 appConfigName 逻辑不一致

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Feb 5, 2021
@luckyadam
Copy link
Member

配置文件不支持这样加后缀区分平台,可以在 app.config 里用逻辑判断来做
https://docs.taro.zone/docs/envs#appjs-%E4%B8%AD%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%90%8C%E7%9A%84-pages

@mrzzcn
Copy link
Author

mrzzcn commented Feb 7, 2021

@luckyadam 我创建 app.weapp.tsx app.weapp.config.ts 这样也报错。这样也必须用 同一个配置文件来做吗

@Chen-jj
Copy link
Contributor

Chen-jj commented Feb 19, 2021

@luckyadam 我创建 app.weapp.tsx app.weapp.config.ts 这样也报错。这样也必须用 同一个配置文件来做吗

@mrzzcn 目前只支持 app.config.ts,楼上正解,你可以在 app.config.ts 里写 if else 来处理多端逻辑。

@Chen-jj Chen-jj closed this as completed Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

3 participants