Tencent / wepy

小程序组件化开发框架
https://wepyjs.gitee.io/wepy-docs/
Other
22.55k stars 3.05k forks source link

npm run build 时报错 Unexpected token: punc ()) #1437

Closed tonychen0716 closed 6 years ago

tonychen0716 commented 6 years ago

Description

npm run build 时报错 [Error] {"message":"Unexpected token: punc ())","filename":0,"line":84,"col":19,"pos":2306} npm run dev不报类似错误

[Description of the issue]

Environment

Reproduce

部分package.json

"dependencies": { "mockjs-little": "^1.0.1-beta3", "redux": "^4.0.0", "redux-actions": "^2.4.0", "redux-promise": "^0.5.3", "wafer2-client-sdk": "^1.1.3", "wepy": "^1.7.1", "wepy-async-function": "^1.4.4", "wepy-com-toast": "^1.0.1", "wepy-redux": "^1.5.9" }, "devDependencies": { "babel-eslint": "^7.2.1", "babel-plugin-syntax-export-extensions": "^6.13.0", "babel-plugin-transform-decorators-legacy": "^1.3.5", "babel-plugin-transform-export-extensions": "^6.22.0", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-1": "^6.24.1", "cross-env": "^3.2.4", "eslint": "^3.18.0", "eslint-config-standard": "^7.1.0", "eslint-friendly-formatter": "^2.0.7", "eslint-plugin-html": "^2.0.1", "eslint-plugin-promise": "^3.8.0", "eslint-plugin-standard": "^2.0.1", "wepy-compiler-babel": "^1.5.3", "wepy-compiler-less": "^1.3.12", "wepy-compiler-sass": "^1.3.12", "wepy-eslint": "^1.5.4", "wepy-plugin-autoprefixer": "^1.5.10", "wepy-plugin-filemin": "^1.3.12", "wepy-plugin-imagemin": "^1.5.2", "wepy-plugin-uglifyjs": "^1.3.6" }

tonychen0716 commented 6 years ago
// wepy.config.js
const prod = process.env.NODE_ENV === 'production';

module.exports = {
  wpyExt: '.wpy',
  build: {
    web: {}
  },
  eslint: true,
  compilers: {
    sass: {
      outputStyle: 'compact'
    },
    babel: {
      sourceMap: true,
      presets: [
        'es2015',
        'stage-1'
      ],
      plugins: [
        'transform-decorators-legacy',
        'transform-export-extensions',
        'syntax-export-extensions'
      ]
    }
  },
  plugins: {
    'autoprefixer': {
      filter: /\.(wxss|css)$/,
      config: {
        browsers: ['last 11 iOS versions']
      }
    }
  }
};

if (prod) {
  delete module.exports.compilers.babel.sourcesMap;
  // 压缩sass
  module.exports.compilers['sass'] = {
    outputStyle: 'compressed'
  };

  // 压缩js
  module.exports.plugins = {
    autoprefixer: {
      filter: /\.(wxss|css)$/,
      config: {
        browsers: ['last 11 iOS versions']
      }
    },
    uglifyjs: {
      filter: /\.js$/,
      config: {}
    },
    filemin: {
      filter: /\.(wxml)$/
    },
    imagemin: {
      filter: /\.(jpg|png|jpeg)$/,
      config: {
        jpg: {
          quality: 80
        },
        png: {
          quality: 80
        }
      }
    }
  };
}
tonychen0716 commented 6 years ago

去掉wafer2-client-sdk就过了

some-code commented 6 years ago

遇到了同样的错误,但是我不能去掉 wafer2-client-sdk ,请问该如何解决?

some-code commented 6 years ago

已解决,把 wafer-client-sdk 文件夹放入 src 目录下,然后修改引入方式即可。bug原因是因为此npm包发布前未编译。

tonychen0716 commented 6 years ago

@some-code 厉害

code-manito commented 6 years ago

没有wafer-client-sdk这个报错怎么解决 wepy v1.6.0