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

压缩错误 #2812

Closed
ccqgithub opened this issue Apr 18, 2019 · 10 comments
Closed

压缩错误 #2812

ccqgithub opened this issue Apr 18, 2019 · 10 comments

Comments

@ccqgithub
Copy link

问题描述

打包生成环境报压缩错误, 错误信息如下

错误  压缩错误  文件/Users/season/Documents/work/pusihotels/node_modules/query-string/index.js
{ SyntaxError: Unexpected token: keyword «const»
    at JS_Parse_Error.get (eval at <anonymous> (/Users/season/Documents/work/pusihotels/node_modules/uglify-js/tools/node.js:20:1), <anonymous>:71:23)
    at formatError (internal/util/inspect.js:817:16)
    at formatRaw (internal/util/inspect.js:616:14)
    at formatValue (internal/util/inspect.js:511:10)
    at inspect (internal/util/inspect.js:191:10)
    at Object.formatWithOptions (util.js:84:12)
    at Console.(anonymous function) (console.js:191:15)
    at Console.log (console.js:202:31)
    at recursiveRequire (/Users/season/.nvm/versions/node/v10.15.1/lib/node_modules/@tarojs/cli/src/util/resolve_npm_files.js:210:19)
    at resolveNpmFilesPath (/Users/season/.nvm/versions/node/v10.15.1/lib/node_modules/@tarojs/cli/src/util/resolve_npm_files.js:72:5)
  message: 'Unexpected token: keyword «const»',
  filename: '0',
  line: 3,
  col: 0,
  pos: 15 }

复现步骤
项目中用了query-string npm包,里面好像有es6代码没有转换位es5,压缩报错

期望行为
不报错,正确压缩

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

Taro CLI 1.2.26 environment info:
   System:
     OS: macOS 10.14.3
     Shell: 5.3 - /bin/zsh
   Binaries:
     Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
     npm: 6.4.1 - ~/.nvm/versions/node/v10.15.1/bin/npm
@taro-bot
Copy link

taro-bot bot commented Apr 18, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@code-artisan
Copy link

我也遇到了,官方没计划修复这个问题么?

@Darmody
Copy link

Darmody commented Jun 19, 2019

+1

1 similar comment
@laiyaoWeb
Copy link

+1

@melochale
Copy link

我也遇到了,请问有什么办法可以解决吗?

@zephyrpersonal
Copy link

query-string可以通过安装query-string@5解决

暴力方案:

config/prod.js里关闭uglifyJS

module.exports = {
  //...other
  plugins: {
    uglify: {
      enable: false,
      config: {
        // 配置项同 https://github.com/mishoo/UglifyJS2#minify-options
      },
    },
  }
}

@yuche
Copy link
Contributor

yuche commented Aug 15, 2019

这个问题一般是 node_modules 使用了 ES6 模块的缘故,这在 Taro 中是不行的

@taro-bot
Copy link

taro-bot bot commented Aug 15, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@taro-bot taro-bot bot removed the to be closed label Aug 30, 2019
@taro-bot taro-bot bot closed this as completed Aug 30, 2019
@codeyourwayup
Copy link

对的,需要安装query-string 5
query-strinstring 6不行的

image

@LJJCherry
Copy link

这个问题一般是 node_modules 使用了 ES6 模块的缘故,这在 Taro 中是不行的

#871 (comment) 支持了这个配置也不行吗

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

9 participants