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

在项目根目录中 config 文件夹的 index.jsdev.js 中的 config 对象均未声明 plugins 属性的情况下,开发环境编译小程序时会报错:TypeError: Cannot read property 'uglify' of undefined #4101

Closed
lexmin0412 opened this issue Aug 7, 2019 · 12 comments
Assignees

Comments

@lexmin0412
Copy link
Contributor

问题描述
在项目根目录中 config 文件夹的 index.jsdev.js 中的 config 对象均未声明 plugins 属性的情况下,开发环境编译小程序时会报错:TypeError: Cannot read property 'uglify' of undefined

复现步骤

  1. 注释 config/index.jsconfig 对象的 plugins 属性声明
const config = {
	date: '2019-04-01',
	designWidth: 750,
	deviceRatio: {
		'640': 2.34 / 2,
		'750': 1,
		'828': 1.81 / 2
	},
	alias: {
		'~/': path.resolve(__dirname, '..', 'src/'),
		'~/components': path.resolve(__dirname, '..', 'src/components'),
		'~/config': path.resolve(__dirname, '..', 'src/config'),
		'~/constants': path.resolve(__dirname, '..', 'src/constants'),
		'~/enums': path.resolve(__dirname, '..', 'src/enums'),
		'~/interceptors': path.resolve(__dirname, '..', 'src/interceptors'),
		'~/interfaces': path.resolve(__dirname, '..', 'src/interfaces'),
		'~/models': path.resolve(__dirname, '..', 'src/models'),
		'~/pages': path.resolve(__dirname, '..', 'src/pages'),
		'~/services': path.resolve(__dirname, '..', 'src/services'),
		'~/utils': path.resolve(__dirname, '..', 'src/utils'),
		'~/styles': path.resolve(__dirname, '..', 'src/styles'),
		'~/assets': path.resolve(__dirname, '..', 'src/assets')
	},
	// plugins: { },   // 看这里,注释掉了
	sourceRoot: 'src',
	outputRoot: 'dist',
};
  1. 启动开发环境: yarn dev:weapp
  2. 报错:
TypeError: Cannot read property 'uglify' of undefined
    at ImportDeclaration (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\@tarojs\cli\dist\mini\astProcess.js:398:63)
    at NodePath._call (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:76:18)
    at NodePath.call (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:48:17)
    at NodePath.visit (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:105:12)
    at TraversalContext.visitQueue (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:150:16)
    at TraversalContext.visitMultiple (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:103:17)
    at TraversalContext.visit (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:190:19)
    at Function.traverse.node (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\index.js:114:17)
    at NodePath.visit (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:115:19)
    at TraversalContext.visitQueue (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:150:16)

期望行为
期望 @tarojs\cli / dist / mini / astProcess.js 文件在获取 projectconfig.plugins 对象的属性时能够兼容 config 对象中未定义 plugins 的情况,(如第398/399/514/515/809/810行)

uglify: projectConfig.plugins.uglify || { enable: true },  // 这里需要先判断projectConfig.plugins存在

报错信息

TypeError: Cannot read property 'uglify' of undefined
    at ImportDeclaration (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\@tarojs\cli\dist\mini\astProcess.js:398:63)
    at NodePath._call (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:76:18)
    at NodePath.call (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:48:17)
    at NodePath.visit (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:105:12)
    at TraversalContext.visitQueue (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:150:16)
    at TraversalContext.visitMultiple (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:103:17)
    at TraversalContext.visit (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:190:19)
    at Function.traverse.node (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\index.js:114:17)
    at NodePath.visit (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\path\context.js:115:19)
    at TraversalContext.visitQueue (D:\0_PROJECT_BOX\mygroup\myapp\node_modules\babel-traverse\lib\context.js:150:16)

系统信息

👽 Taro v1.3.12

  Taro CLI 1.3.12 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 10.3.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.14.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
      npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
@taro-bot
Copy link

taro-bot bot commented Aug 7, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Aug 15, 2019

CC @luckyadam

@YMaster
Copy link

YMaster commented Jan 16, 2020

问题解决了吗?最新的 beta.13 还是这个问题,所有的平台均以不同的报错无法运行

@Garfield550
Copy link
Collaborator

@YMaster 你注释了什么配置项目,我用 Taro 2.0.1 测试默认模版,注释 config/index.js 里的 plugins: [], 没有复现任何问题。

image

@newwangyiyang
Copy link

同样出现此问题,出现模板: typescript

@Garfield550
Copy link
Collaborator

@newwangyiyang 请问是默认模版并启用 TypeScript 吗?Taro 版本是多少?运行的命令是什么?

@newwangyiyang
Copy link

@Garfield550 是的,启用了Typescript; Taro版本: Taro v2.0.1; 运行命令: yarn dev:weapp; 未启用typescript也出现同样问题;加上 "plugins:[]",可正常编译通过

@Garfield550 Garfield550 assigned Garfield550 and unassigned luckyadam Jan 21, 2020
@Garfield550
Copy link
Collaborator

@newwangyiyang 我使用 2.0.1 新建了使用 TypeScript 的默认模版项目,注释 config/index.jsplugins: [],,运行 yarn dev:weapp 没有复现问题。

麻烦可以提供一下更详细的 config 配置(包含 dev 和 prod)或者发一份复现项目上来吗?

@Garfield550
Copy link
Collaborator

image

@newwangyiyang
Copy link

我这边问题已解决,定位问题是: 初始化项目,跟运行时项目taro版本不一致,报'uglify' undefined错误

@taro-bot
Copy link

taro-bot bot commented Jan 21, 2020

CC @luckyadam

@Garfield550
Copy link
Collaborator

先关闭掉了,如果其他人有遇到此问题请另外告知。

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

6 participants