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

2.0.0-beta.8. 编译RN报错 'babel' of undefined #5093

Closed
zhougonglai opened this issue Dec 16, 2019 · 5 comments
Closed

2.0.0-beta.8. 编译RN报错 'babel' of undefined #5093

zhougonglai opened this issue Dec 16, 2019 · 5 comments
Assignees

Comments

@zhougonglai
Copy link

问题描述

Taro v2.0.0-beta.8 生产的项目在运行 npm run dev:rn报错

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'babel' of undefined
.nvm/versions/node/v13.0.1/lib/node_modules/@tarojs/cli/dist/rn.js:50:55

>49   this.rnConfig = this.projectConfig.rn || {};
>50   this.babelConfig = this.projectConfig.plugins.babel; // 用来配置 babel
>51    // 直接输出编译后代码到指定目录
>52  if (this.rnConfig.outPath) {

复现步骤

  1. taro init myApp
  2. write in package "@tarojs/taro-rn": "2.0.0-beta.8"
  3. npm i && npm run dev:rn
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'babel' of undefined
.nvm/versions/node/v13.0.1/lib/node_modules/@tarojs/cli/dist/rn.js:50:55

>49   this.rnConfig = this.projectConfig.rn || {};
>50   this.babelConfig = this.projectConfig.plugins.babel; // 用来配置 babel
>51    // 直接输出编译后代码到指定目录
>52  if (this.rnConfig.outPath) {
/**
 * 这段注释后可以贴代码
 * 提供完整可复现的代码和整理好代码格式,有助于我们快速定位问题,节省你我时间
 * 代码提供不全或代码格式混乱的 issues 【有可能会被忽略】
 * 
 * 查看如何插入代码:https://coding.net/help/doc/project/markdown.html#i-5
 */

期望行为

正常运行 RN

报错信息

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'babel' of undefined
.nvm/versions/node/v13.0.1/lib/node_modules/@tarojs/cli/dist/rn.js:50:55

>49   this.rnConfig = this.projectConfig.rn || {};
>50   this.babelConfig = this.projectConfig.plugins.babel; // 用来配置 babel
>51    // 直接输出编译后代码到指定目录
>52  if (this.rnConfig.outPath) {

系统信息

System:
      OS: macOS 10.15.1
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 13.0.1 - ~/.nvm/versions/node/v13.0.1/bin/node
      Yarn: 1.21.1 - ~/.nvm/versions/node/v13.0.1/bin/yarn
      npm: 6.13.4 - ~/.nvm/versions/node/v13.0.1/bin/npm
    npmPackages:
      @tarojs/components: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/components-qa: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/mini-runner: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/mobx: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/mobx-h5: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/router: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-alipay: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-h5: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-qq: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-quickapp: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-rn: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-swan: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-tt: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/taro-weapp: 2.0.0-beta.8 => 2.0.0-beta.8 
      @tarojs/webpack-runner: 2.0.0-beta.8 => 2.0.0-beta.8 
      eslint-config-taro: 2.0.0-beta.8 => 2.0.0-beta.8 
      eslint-plugin-taro: 2.0.0-beta.8 => 2.0.0-beta.8 
      nerv-devtools: ^1.5.5 => 1.5.6 
      nervjs: ^1.5.5 => 1.5.6 
      stylelint-config-taro-rn: 2.0.0-beta.8 => 2.0.0-beta.8 
      stylelint-taro-rn: 2.0.0-beta.8 => 2.0.0-beta.8

补充信息

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

@taro-bot
Copy link

taro-bot bot commented Dec 16, 2019

CC @luckyadam

@taro-bot
Copy link

taro-bot bot commented Dec 16, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@shenghanqin
Copy link
Collaborator

@zhougonglai 贴一下完整的package.json和configs/index.js吧。
taro init后的config/index.js估计不是2.0.0版本吧,你可以看看配置说明,确认一下。因为里面的babel是需要重新配置的。

@zhougonglai
Copy link
Author

@zhougonglai 贴一下完整的package.json和configs/index.js吧。
taro init后的config/index.js估计不是2.0.0版本吧,你可以看看配置说明,确认一下。因为里面的babel是需要重新配置的。

package.json

"dependencies": {
		"@tarojs/components": "2.0.0-beta.8",
		"@tarojs/components-qa": "2.0.0-beta.8",
		"@tarojs/mobx": "2.0.0-beta.8",
		"@tarojs/mobx-h5": "2.0.0-beta.8",
		"@tarojs/router": "2.0.0-beta.8",
		"@tarojs/taro": "2.0.0-beta.8",
		"@tarojs/taro-alipay": "2.0.0-beta.8",
		"@tarojs/taro-h5": "2.0.0-beta.8",
		"@tarojs/taro-qq": "2.0.0-beta.8",
		"@tarojs/taro-quickapp": "2.0.0-beta.8",
		"@tarojs/taro-swan": "2.0.0-beta.8",
		"@tarojs/taro-tt": "2.0.0-beta.8",
		"@tarojs/taro-rn": "2.0.0-beta.8",
		"@tarojs/taro-weapp": "2.0.0-beta.8",
		"mobx": "4.8.0",
		"nerv-devtools": "^1.5.5",
		"nervjs": "^1.5.5",
		"taro-ui": "^2.2.4"
	},
	"devDependencies": {
		"@types/react": "^16.4.6",
		"@types/webpack-env": "^1.13.6",
		"@tarojs/mini-runner": "2.0.0-beta.8",
		"@tarojs/webpack-runner": "2.0.0-beta.8",
		"babel-plugin-transform-class-properties": "^6.24.1",
		"babel-plugin-transform-decorators-legacy": "^1.3.4",
		"babel-plugin-transform-jsx-stylesheet": "^0.6.5",
		"babel-plugin-transform-object-rest-spread": "^6.26.0",
		"babel-preset-env": "^1.6.1",
		"babel-eslint": "^8.2.3",
		"eslint": "^5.16.0",
		"eslint-config-taro": "2.0.0-beta.8",
		"eslint-plugin-react": "^7.8.2",
		"eslint-plugin-react-hooks": "^1.6.1",
		"eslint-plugin-import": "^2.12.0",
		"stylelint": "9.3.0",
		"stylelint-config-taro-rn": "2.0.0-beta.8",
		"stylelint-taro-rn": "2.0.0-beta.8",
		"eslint-plugin-taro": "2.0.0-beta.8",
		"@typescript-eslint/parser": "^1.6.0",
		"typescript": "^3.0.1"
	}

configs/index.js

const config = {
	projectName: 'konfood',
	date: '2019-12-13',
	designWidth: 750,
	deviceRatio: {
		'640': 2.34 / 2,
		'750': 1,
		'828': 1.81 / 2,
	},
	sourceRoot: 'src',
	outputRoot: 'dist',
	babel: {
		sourceMap: true,
		presets: [
			[
				'env',
				{
					modules: false,
				},
			],
		],
		plugins: [
			'transform-decorators-legacy',
			'transform-class-properties',
			'transform-object-rest-spread',
		],
	},
	defineConstants: {},
	mini: {
		postcss: {
			autoprefixer: {
				enable: true,
				config: {
					browsers: ['last 3 versions', 'Android >= 4.1', 'ios >= 8'],
				},
			},
			pxtransform: {
				enable: true,
				config: {},
			},
			url: {
				enable: true,
				config: {
					limit: 10240, // 设定转换尺寸上限
				},
			},
			cssModules: {
				enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
				config: {
					namingPattern: 'module', // 转换模式,取值为 global/module
					generateScopedName: '[name]__[local]___[hash:base64:5]',
				},
			},
		},
	},
	h5: {
		publicPath: '/',
		staticDirectory: 'static',
		esnextModules: ['taro-ui'],
		postcss: {
			autoprefixer: {
				enable: true,
				config: {
					browsers: ['last 3 versions', 'Android >= 4.1', 'ios >= 8'],
				},
			},
			cssModules: {
				enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
				config: {
					namingPattern: 'module', // 转换模式,取值为 global/module
					generateScopedName: '[name]__[local]___[hash:base64:5]',
				},
			},
		},
	},
};

module.exports = function(merge) {
	if (process.env.NODE_ENV === 'development') {
		return merge({}, config, require('./dev'));
	}
	return merge({}, config, require('./prod'));
};

@taro-bot
Copy link

taro-bot bot commented Dec 17, 2019

CC @Pines-Cheng

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

4 participants