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.0-rc.3] babel preset targets 配置无效 #6547

Closed
charmtiger opened this issue Jun 3, 2020 · 3 comments
Closed

[Taro 3.0.0-rc.3] babel preset targets 配置无效 #6547

charmtiger opened this issue Jun 3, 2020 · 3 comments
Assignees

Comments

@charmtiger
Copy link

charmtiger commented Jun 3, 2020

问题描述

h5 在chrome 42 中空白,console 中显示 Uncaught SyntaxError: Unexpected token )
npm run build:h5 代码中仍有 const , () => {}。

复现步骤

babel.config.js

module.exports = {
  sourceMap: true,
  presets: [
    ['taro', {
      framework: 'react',
      ts: true,
      targets: {
        // ios: 7,
        // android: 4,
        chrome: '42'
      }
    }]
  ]
}

系统信息

Taro CLI 3.0.0-alpha.7 environment info:
System:
OS: macOS 10.15.4
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
Yarn: 1.22.4 - ~/.config/yarn/global/node_modules/.bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
npmPackages:
@tarojs/cli: 3.0.0-rc.3 => 3.0.0-rc.3
@tarojs/components: 3.0.0-rc.3 => 3.0.0-rc.3
@tarojs/taro: 3.0.0-rc.3 => 3.0.0-rc.3
@tarojs/webpack-runner: 3.0.0-rc.3 => 3.0.0-rc.3
eslint-config-taro: 3.0.0-rc.3 => 3.0.0-rc.3
nerv-devtools: ^1.5.6 => 1.5.6
nervjs: ^1.5.6 => 1.5.6
react: ^16.10.0 => 16.13.1

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 3, 2020

@charmtiger 进入 node_modules/babel-preset-taro/index.js 打印一下 target 调试一下?

@charmtiger
Copy link
Author

@Chen-jj 尝试在最下方打印

  console.log('[presets] ', presets[0][1]);
  return {
    sourceType: 'unambiguous',
    overrides: [{
      exclude: [/@babel[/|\\\\]runtime/, /core-js/],
      presets,
      plugins
    }]
  }

结果如下

[presets]  {
  spec: undefined,
  loose: false,
  debug: false,
  modules: false,
  targets: { chrome: '42' },
  useBuiltIns: false,
  ignoreBrowserslistConfig: false,
  configPath: undefined,
  include: undefined,
  exclude: undefined,
  shippedProposals: undefined,
  forceAllTransforms: undefined
}

yuche added a commit that referenced this issue Jun 8, 2020
close #6547
babel 不会转换 loader 生成的代码
@yuche yuche closed this as completed Jun 9, 2020
@charmtiger
Copy link
Author

charmtiger commented Jun 18, 2020

@yuche 升级到 rc.5 如此配置仍然不可运行,如下图所示 报错 Unexpected strict mode reserved word。另外我还在 chrome 38 41 44 中尝试,报错 Object.assign is not a function
配置

module.exports = {
  sourceMap: false,
  presets: [
    ['taro', {
      framework: 'react',
      ts: true,
      targets: {
        ios: '7',
        android: '4',
        // chrome: '44'
      }
    }]
  ]
}

以下环境是 android 4.4 模拟器
image

  Taro CLI 3.0.0-alpha.7 environment info:
    System:
      OS: macOS 10.15.4
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.16.1 - ~/.nvm/versions/node/v12.16.1/bin/node
      Yarn: 1.22.4 - ~/.config/yarn/global/node_modules/.bin/yarn
      npm: 6.13.4 - ~/.nvm/versions/node/v12.16.1/bin/npm
    npmPackages:
      @tarojs/cli: 3.0.0-rc.5 => 3.0.0-rc.5 
      @tarojs/components: 3.0.0-rc.5 => 3.0.0-rc.5 
      @tarojs/taro: 3.0.0-rc.5 => 3.0.0-rc.5 
      @tarojs/webpack-runner: 3.0.0-rc.5 => 3.0.0-rc.5 
      eslint-config-taro: 3.0.0-rc.5 => 3.0.0-rc.5 
      nerv-devtools: ^1.5.6 => 1.5.7 
      nervjs: ^1.5.6 => 1.5.7 
      react: ^16.10.0 => 16.13.1 

npm run build:h5 产出的代码 只有 app.xxx.js 中包含 const 、Object.assign

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

3 participants