12-14-2018 18:44 - edited 12-14-2018 18:44
12-14-2018 18:44 - edited 12-14-2018 18:44
Hello,
currently, I am trying to create an npm module and I already have published it here. Actually, the function works. But when I try to import it, I do always get the same error:
[error][build] companion.js GulpUglifyError: unable to minify JavaScript
I have imported the file in that way:
import requestGraphQL from "graphql-fitbit";
Now when I call the function I will get the error above:
requestGraphQL(graphql_url, query).then(data => console.log(data));
I know that maybe my code is stupid for just that case, but I want to understand how to use NPM modules in Fitbit projects.
Thank you for your help in advance.
Answered! Go to the Best Answer.
12-15-2018 04:17
12-15-2018 04:17
I think you can't use ES6 syntax in modules, but I think David worked around that by importing the fitbit-sdk into his project. See https://www.npmjs.com/package/fitbit-asap
12-15-2018 04:17
12-15-2018 04:17
I think you can't use ES6 syntax in modules, but I think David worked around that by importing the fitbit-sdk into his project. See https://www.npmjs.com/package/fitbit-asap
12-16-2018 04:36 - edited 12-16-2018 04:38
12-16-2018 04:36 - edited 12-16-2018 04:38
Thanks Jon,
I found out what the problem actually was. The GulpUglify minimizer does not support async functions with an awaiting return. So I switched to traditional callbacks and it worked. Probably all the ES6 syntax does not work, unfortunately.
12-17-2018 04:01
12-17-2018 04:01
You'll want to use something like TypeScript or Babel to transpile your module before publishing.
You can find a Babel example here: https://github.com/gregoiresage/fitfont/blob/develop/package.json#L4-L15
The example Jon mentioned uses TypeScript here: https://github.com/dillpixel/fitbit-asap/blob/master/package.json#L22