Get 'Zone already loaded' error in Rails + webpack + angular 2 initial setup

153 views Asked by At

I used following specifications.

1) rails 5.1.3

2) ruby 2.4.1

3) rail with webpacker

4) Angular 4.3.4 with webpacker (Typescript)

I create new rail app using command rails new my-rails-app --webpack-angular.

Folder structure

enter image description here

After that, as per instruction under app/javascript/packs/application.js and app/javascript/packs/hello_angular.js, I added <%= javascript_pack_tag 'application' %> in application.html.erb to head tag next after javascript_include_tag.

Also add below markup to body tag in layout application.html.erb

// <hello-angular>Loading...</hello-angular>
//
// <%= javascript_pack_tag 'hello_angular' %>

application.html.erb

<!DOCTYPE html>
<html>
  <head>
    <title>AngularOnRailsWithWebpack</title>
    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application' %>
  </head>

  <body>
    <hello-angular>Loading...</hello-angular>
    <%= javascript_pack_tag 'hello_angular' %>
    <%= yield %>
  </body>
</html>

Now create new scaffolding by running rails g scafolld post title:string desc:text and set post index page as root path

Now run rails server by running rails s and webpack server by running ./bin/webpack-dev-server

Works fine.

But When I navigate routes by click on new post or edit post it fire errors in web console like below.

enter image description here

Solution I tried

1) Remove javascript_include_tag from application.html.erb. But it will remove turbolink. I don't want to remove that.

2) Restore javascript_include_tag and update index.ts under app/javascript/hello-angular/index.ts. Add turbolink load event as per this video instruction https://www.youtube.com/watch?v=lGToT9RyDxc

Index.ts

import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

document.addEventListener('turbolinks:load', () => {
  platformBrowserDynamic().bootstrapModule(AppModule);
})

Work fine. It will render code fine but still same zone error in web console.

enter image description here

May be this is rails issue. If so then I hope it will resolve in next patch release.

Can any one help that how to resolve this issue ? What I am doing wrong.

0

There are 0 answers