dialogflow / dialogflow-javascript-client

JavaScript Web SDK for Dialogflow
Apache License 2.0
412 stars 173 forks source link

Breaks any build process w/ UglifyJS because main export is not ES2015 #68

Open DroopyTersen opened 6 years ago

DroopyTersen commented 6 years ago

Most developers exclude node_modules packages from their build process (typescript or es6). Therefore if you provide an ES6 module, that ES6 is getting injected straight into the bundle as is and won't work in many browsers. It also breaks many build processes that utilize Uglify JS to minify because uglify requires ES5 code.

Typically, packages transpile to a lib folder that contains es5 code or package as an ES5 UMD module.

DroopyTersen commented 6 years ago

Installed using

npm install api-ai-javascript@2.0.0-beta.14
EmandM commented 6 years ago

I am also having this issue.

The common way of supporting Typescript is to provide a typings (.d.ts) file alongside compiled es5 JavaScript. I've had to relax the settings on my Typescript compilation due to this project not adhering to the same Typescript standards. And now UglifyJs is erroring out on code from this package.

Installed using

 npm install api-ai-javascript@2.0.0-beta.21
radi-cho commented 6 years ago

The problem is not only with UglifyJS, But with CRA and Angular, too. - #69 Actually I built my app, and fixed this for me. You can go to node_modules/api-ai-javascript/es6 and compile all files using Babel - https://babeljs.io/repl If someone want to build an app I can help. But hopefully the Dialogflow team will fix this for everyone.

athJ commented 6 years ago

@radi-cho Can you please tell how exactly you complied the files , I am also having the same issue with CRA and Dialogflow team hasn't fixed it yet as there is V2 now.

radi-cho commented 6 years ago

@athJ You can simply copy-paste the code to the babel repl and then overwrite the files in es6. Or you can use babel cli following these instructions: https://babeljs.io/docs/en/babel-cli

athJ commented 6 years ago

@radi-cho Thanks but I figured it out a while after I posted that comment.What I actually did was make a copy of the module outside node_modules and then I complied the whole directory directly into the module folder inside node_modules using "-d" argument with bable-cli