azure-functions-pack icon indicating copy to clipboard operation
azure-functions-pack copied to clipboard

Issue with packing with Uglify on moment.js

Open cmatskas opened this issue 8 years ago • 3 comments

I was testing the funcpack pack --uglify ./ command with a simple HTTPTrigger function that consumes lodash and moment.js. The uglify command fails with the following error message:

c:\Projects\test>funcpack pack --uglify ./
info: Generating project files/metadata
info: Webpacking project
error: Hash: e15c39066dfbe277dec5
Version: webpack 2.2.1
Time: 7867ms
    Asset    Size  Chunks                    Chunk Names
output.js  348 kB       0  [emitted]  [big]  main
chunk    {0} output.js (main) 1.52 MB [entry] [rendered]
    [0] ./testtrigger/~/moment/moment.js 123 kB {0} [built]
    [1] c:/Users/chris/AppData/Roaming/npm/~/azure-functions-pack/~/webpack/buildin/module.js 517 bytes {0} [built]
    [8] ./testtrigger/~/moment/locale/ar.js 4.12 kB {0} [optional] [built]
   [10] ./testtrigger/~/moment/locale/be.js 4.47 kB {0} [optional] [built]
   [11] ./testtrigger/~/moment/locale/bg.js 2.84 kB {0} [optional] [built]
   [12] ./testtrigger/~/moment/locale/bn.js 3.22 kB {0} [optional] [built]
   [13] ./testtrigger/~/moment/locale/bo.js 3.47 kB {0} [optional] [built]
   [14] ./testtrigger/~/moment/locale/br.js 3.11 kB {0} [optional] [built]
   [62] ./testtrigger/~/moment/locale/lv.js 3.6 kB {0} [optional] [built]
  [110] ./packeddata/index.js 701 bytes {0} [built]
  [111] ./testtrigger/index.js 701 bytes {0} [built]
  [112] ./.funcpack/index.js 127 bytes {0} [built]
  [113] ./~/lodash/lodash.js 540 kB {0} [built]
  [114] ./testtrigger/~/lodash/lodash.js 540 kB {0} [built]
  [115] ./testtrigger/~/moment/locale ^\.\/.*$ 2.61 kB {0} [optional] [built]
     + 101 hidden modules

ERROR in ./packeddata/index.js
Module not found: Error: Can't resolve 'moment' in 'c:\Projects\test\packeddata'
 @ ./packeddata/index.js 2:13-30
 @ ./.funcpack/index.js
(node:17184) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Could not webpack project
(node:17184) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Is this because moment.js implements too many ES6 features? Thanks

cmatskas avatar Mar 14 '17 11:03 cmatskas

In addition, when this fails, rather than revert back to the original state, the function is still packed which means that things would fail if it were for a user to deploy this (not sure why but hey!). My point is that pack execution failures should revert the function to it's original format.

cmatskas avatar Mar 14 '17 11:03 cmatskas

Could you file a specific issue for the "should revert" request? I think that's a good one.

In this case, Uglify looks like it didn't like that you weren't handling a promise rejection. I could probably make it so you could provide some config for uglify, so you could choose to ignore those issues. If you just do a require("moment") and not use it, does it still fail? Ideally you could add a simple repro, if possible.

christopheranderson avatar Mar 14 '17 20:03 christopheranderson

I was just wondering whether an interim solution could be to include babel with es2015 option before uglify in webpack ?

smil2k avatar Apr 16 '17 22:04 smil2k