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

Getting 'Map' is undefined error. #3309

Closed
Shijir opened this issue Nov 29, 2016 · 4 comments · Fixed by #3812
Closed

Getting 'Map' is undefined error. #3309

Shijir opened this issue Nov 29, 2016 · 4 comments · Fixed by #3812
Assignees

Comments

@Shijir
Copy link

Shijir commented Nov 29, 2016

OS?

Windows 7 (running on a VM)

Versions.

angular-cli: 1.0.0-beta.20-4
node: 6.6.0
os: darwin x64

Repro steps.

I am trying to use the custom elements v1 polyfill (custom-elements.min.js) in the angular-cli.json by using the following pattern:

      "scripts": [
        "../node_modules/mutationobserver-shim/dist/mutationobserver.min.js",
        "../node_modules/@webcomponents/custom-elements/custom-elements.min.js",
      ],

This works across all browsers except IE10. In the console, it says:

SCRIPT5009: 'Map' is undefined 

Mention any other details that might be useful.

It logs an error when I try to use it in the scripts section of angular-cli.json. The error will be gone and the polyfill will start working fine if I insert es6-shim in the script:

      "scripts": [
        "../node_modules/es6-shim/es6-shim.min.js",
        "../node_modules/mutationobserver-shim/dist/mutationobserver.min.js",
        "../node_modules/@webcomponents/custom-elements/custom-elements.min.js"
      ],

Here I don't want to use es6-shim because there is core-js/es6/map imported in the polyfills.ts file.

The log error was pointing at the polyfill (https://github.com/webcomponents/custom-elements/blob/master/custom-elements.min.js).

screenshot 2016-11-28 23 56 57

@filipesilva
Copy link
Contributor

I think I know the reason for this. It's true that you have core-js/es6/map in polyfills.ts, but the scripts array is loaded before the main bundle. So custom-elements.min.js never sees the Map shim.

The solution is to add es6-shim to scripts instead of polyfills.ts. Maybe the CLI should do that by default really.

@filipesilva
Copy link
Contributor

Also related to #2752

@Shijir
Copy link
Author

Shijir commented Dec 31, 2016

@filipesilva thank you for the response. Your explanation really helped me to confirm my assumption of what was causing the error. I am wondering why script arrays are loaded before polyfills. In the documentation, it's recommended to have those 3rd party libraries in the scripts array. But there are some libraries that depend on the polyfills such as core-js and other shims. So I thought it would make sense if angular-cli loads those 3rd pary libraries after loading the polyfills.ts.

filipesilva added a commit to filipesilva/angular-cli that referenced this issue Dec 31, 2016
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 1, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 2, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 2, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 3, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 3, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 20, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 20, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 20, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 20, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

Fix angular#2752
Fix angular#3309
filipesilva added a commit that referenced this issue Jan 20, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

This PR loads polyfills as a separate entry point, before everything else.

Extra documentation also added to polyfills.ts.

Fix #2752
Fix #3309
Fix #4140
MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this issue Feb 9, 2017
Polyfills found in polyfills.ts would not be available for scripts due to being loaded in the main bundle only.

This PR loads polyfills as a separate entry point, before everything else.

Extra documentation also added to polyfills.ts.

Fix angular#2752
Fix angular#3309
Fix angular#4140
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants