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

Uncaught ReferenceError: a is not defined with mapbox-gl in production mode #251

Closed
kasunvp opened this issue Oct 24, 2019 · 4 comments
Closed

Comments

@kasunvp
Copy link
Contributor

kasunvp commented Oct 24, 2019

a in the error sometimes becomes n, I suppose due to dynamic naming at minification

Repo for reproduction: https://github.com/kasunvp/mapbox-gl-test (minimal app)

Error with ember serve --prod (can see the error even without the mapbox-gl access token)
Works with ember serve (have to add a mapbox-gl access token to load the map)

The interesting fact is that we've been using ember-auto-import + mapbox-gl for some time now. Had a same kind of issue with a previous version, it was resolved and was working fine after using the ember-auto-import configuration noParse: /(mapbox-gl)\.js$/ as was suggested somewhere. But not anymore with the latest versions.

Also, if the deprecated ember-browserify addon is used instead of ember-auto-import, it works fine too. So must be an issue in ember-auto-import/webpack combo.

Versions:

  • Ember: v3.12.0
  • ember-auto-import: v1.5.3
  • mapbox-gl: v1.4.1
@ef4
Copy link
Collaborator

ef4 commented Oct 24, 2019

Thanks for sharing a working reproduction, I can confirm I see the bug.

@kasunvp
Copy link
Contributor Author

kasunvp commented Oct 25, 2019

@ef4 found the solution. We must exclude the mapbox-gl addon from babel transpilation.
I knew this is related to sort of config passing. So was looking in to the ember-auto-import code and found that there is an undocumented option called skipBabel. Used that to skip the babel transpilation of mapbox-gl and problem is solved now.

Also ember-auto-import is a great tool. Thanks a lot for maintaining it. 💯 to every contributor :-)

@ef4
Copy link
Collaborator

ef4 commented Oct 25, 2019

Thanks for the update. Yes, skipBabel needs to get added to the readme, we have an open issue for that. I think it's a fine workaround to this problem.

But I am still curious exactly what is breaking and I might dig in further. It's a little surprising that it breaks only in production, even after I remove uglify. That implies that either babel or webpack is doing something different in prod that results in invalid code.

@kasunvp
Copy link
Contributor Author

kasunvp commented Oct 25, 2019

That maybe because mapbox is using a separate dev package for the dev build and a transpiled one in prod.

Also I included a PR for the README update. Please let me know how it looks :)

@ef4 ef4 closed this as completed Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants