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

Failed to compile - UglifyJs returns undefined #341

Closed
yormi opened this issue Jan 28, 2019 · 8 comments
Closed

Failed to compile - UglifyJs returns undefined #341

yormi opened this issue Jan 28, 2019 · 8 comments
Labels

Comments

@yormi
Copy link

yormi commented Jan 28, 2019

Is this a bug report?

yes

Environment

  1. node -v: v10.15.0
  2. npm -v: 6.4.1
  3. yarn --version (if you use Yarn): 1.12.3
  4. npm ls create-elm-app -g (if you haven’t ejected):

Then, specify:

  1. Operating system: Arch Linux
  2. Browser and version (if relevant): Not relevant

Steps to Reproduce

I import "@babel/polyfill" and then I get:

$ elm-app build
Creating an optimized production build...
Failed to compile.

static/js/vendors~main.ab89a661.chunk.js from UglifyJs
undefined

If I use elm-app start, no problem

If I comment the babel polyfill, it compiles just fine

If I comment the whole Uglify config in the create-elm-app webpack.config.prog.js, it works well.

My guess would be that I should avoid mixing up the babel polyfill with Uglify but I'm not sure how to do that. I used the exclude option (exclude: '@babel/polyfill') of Uglify in webpack.config.prog.js but no success. I guess it's already included in the chunk and therefore processed by the Uglify plugin.

It feels like there's a simple solution but I don't understand the process very well. I'm not even sure why it breaks with ReferenceError: regeneratorRuntime is not defined if I dont use the babel polyfill. From the stack trace it seems to come from customElements.define.

Edit I just saw @babel/plugin-transform-runtime in the webpack config... so why would I get the regeneratorRuntime error then !?

I'll keep investigating but in the meantime, I thought someone could have some useful info to share :)

Let me know what else could be useful !

Thanks for your really helpful work !

Guillaume

@halfzebra
Copy link
Owner

Hi Guillaume!

We have babel-preset-env already, so maybe it would be helpful to learn about your goals. Is there something specific you want to polyfill?

@yormi
Copy link
Author

yormi commented Feb 8, 2019

Hi halfzebra !

Ok so I thought it was related to the Custom Element I use but after looking into it again, I realized that I need the polyfill to use a library that uses ES6.

I thought it was easier to import the babel polyfill than ejecting create-elm-app and change the webpack config to use babel on that library. The problem is that when I run elm-app build, uglify seems to error and cancel the build when it runs on the polyfill.

Any idea if there is a clean solution to use that ES6 library ?

Thanks again !

@Jonsey
Copy link

Jonsey commented Mar 9, 2019

Hi Guillaume,

I'm having exactly the same issue, did you solve the problem?

@yormi
Copy link
Author

yormi commented Mar 9, 2019

Hi Jonsey !

No... I didn't find a clean solution =/

I'm looking back at my commits and apparently, I just downgraded the lib to a version that was not depending on ES6...

I'm very keen to hear about your solution if you find one :)

Good luck !

@Jonsey
Copy link

Jonsey commented Mar 9, 2019

I did a clean elm-app create and only added

`test();

const test = async () => {
  console.log("Worked");
}`

this gave me ReferenceError: regeneratorRuntime is not defined when running elm-app build

@Jonsey
Copy link

Jonsey commented Mar 10, 2019

OK, I fixed it, sort of. I'm not sure why the existing set up with @babel/runtime-generator isn't working, but I removed @babel/polyfil from my index.js and added require('regenerator-runtime/runtime');

I know it pollutes the global namespace but I can now compile in debug and production mode

@yormi
Copy link
Author

yormi commented Mar 10, 2019

Well done @Jonsey ! That is a way better workaround than downgrading the libs !

And I tip my hat to you @halfzebra for the quick PR :)

@halfzebra
Copy link
Owner

🎉 This issue has been resolved in version 3.0.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants