#angular/service-worker silent failure - angular-service-worker

I have used the #angular/service-worker module successfully in several projects but am running into a silent failure issue on my latest project that I can't seem to debug. My configuration and setup is identical to other projects, and the outputted build (via CLI v1.6.2) seems correct:
dist (partial)
My initial thought was there was something wrong with my environment variable so I went through logging to ensure enabled was true after build, even went as far as hardcoding it in all environments just to test:
ServiceWorkerModule.register('/ngsw-worker.js', {
enabled: true
})
Yet still when I run the app, whether locally with http-server or in a dev or qa environment with prod mode enabled there is no service worker registered in dev tools and no errors or warnings in the console:
service worker tab
Does anyone have any ideas what could be causing a silent failure in this case? I have wracked my brain, compared working solutions vs this and cannot seem to come up with a solution. Also, is there any way to further debug this type of scenario?
Thanks in advance for any help!

You can use this workaround in your main.ts file:
platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('/ngsw-worker.js');
}
}).catch(err => console.log(err));
As explained here there may be some problems in your codebase or in your dependencies. I prefer use the workaround for now until an official solution is given by the angular team.

Related

Travis builds are failing with fatal listen error

My Travis tests for a Rails app have been working fine, but have suddenly started failing about one time in three with:
$ bundle exec rails test
FATAL: Listen error: unable to monitor directories for changes.
Visit
https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
for info on how to fix this.
Looking at that suggested URL, it proposes ways to increase the number of inotify-watchers, but requires the use of sudo to change the limit. That's fine on my dev machine (though I'm actually not experiencing the error on my machine), but I don't know if that's possible (or advisable) in the Travis environment.
I looked at the Travis docs to see if there's a config setting for increasing the number of watchers, but I couldn't find anything.
So: what's the best way to deal with this error in a Travis CI test?
If you're running this on TravisCI and a CI/staging/testing server, you should not need to watch files for changes. The code should be deployed to the server, and then bundle exec rails test should run and that's it. No file watching necessary.
What I suspect is that the config for your environment is not set up correctly and that listen gem is somehow activated for the testing environment when it should only be activated for the development environment.
Try running the tests locally with the same environment as TravisCI (testing in this example):
RAILS_ENV=testing bundle exec test
and see what it says. If it gives you that error, check the config/environments/testing.rb file and look for config.cache_classes.
When config.cache_classes is set to true, the classes are cached and the listen/file-watcher will not be active. In your local development environment, config/environments/development.rb, the config.cache_classes setting should be set to false so that file-watching and reloading happens.

WebStorm + webpacker debugging

Hello StackOverflow community!
My team is working on a ruby on rails project, where some parts are written in react. We are using webpacker gem to bundle js files into packs.
I'm trying to set up WebStorm to work with our project, but I have problems with the debugger - webstorm is not hitting any breakpoints.
I'm launching rails s and ./bin/webpack-dev-server in separate terminal instances, installed chrome extension and created JavaScript Debug configuration, pointing to the view where react app resides (on the port 3000). Also added devtool: 'eval' to webpack configuration. In the chrome dev tools I see webpack:// source and I can successfully set breakpoints there.
How to configure this tooling to have breakpoints working?
normally all you need for debugging apps bundled with webpack is to make sure that sourcemaps are properly generated. The best choice here is devtool: 'source-map' (see https://webpack.js.org/configuration/devtool/). eval sourcemaps are not accurate and not too suitable for debugging (quality is "generated code" rather than "original code").
In some cases, you might also need to specify URL mappings - see https://blog.jetbrains.com/webstorm/2015/09/debugging-webpack-applications-in-webstorm/ for more info.
But there are no generic instructions that would work for each and every configuration - as you can configure webpack in dozens of ways. So I can hardly advise on exact steps unless you provide a project you are trying to debug

How to programmatically know if I am building with -prod flag (ng build -prod)

I am using docker so, in production mode I am using linked containers with URLs like "http://api:3000/"
instead of "http://localhost:3000/" while in dev mode.
I would like to be able to use "http://api:3000/" if "ng build -prod" and stay with "localhost" while developing.
How can I do my if( "-prod" ) ?
Thanks for reading me, I hope my question is clear.
EDIT: Everything was explain in a commentary in environment.ts
You have environments/environment.ts, and there is a json
export const environment = {
production = false
};
And you can access it within your application with importing it and then using it with if(environment.production)
or use the built in angular module like in
How to check if Angular 2 app is running in production or dev

Deployment to heroku of Heaven fail

I'm now trying to optimize my team's work flow using slack with Heaven and hubot.
But something strange happened while I deploy heaven to heroku by heroku deploy button.(https://github.com/atmos/heaven)
I've filled in:
GITHUB_TOKEN(permission: gist, repo, user)
GITHUB_CLIENT_ID
GITHUB_CLIENT_SECRET
GITHUB_TEAM_ID
HEROKU_API_KEY
I know the HEROKU_API_KEY is optional,
but whether I fill it or not,
the error messages is still the same.
Here's the error message I met.
http://i.stack.imgur.com/kwtx3.png
Run scripts & scale dynos
There was an issue while running the post deploy script.
Can't find any issue related,
so I thought I might make a stupid mistake.

My new password page says 404 in production mode only

http://site.com/users/password/new is returning a 404 in production mode but not in development. I am deploying via capistrano and it looks like it's copying the entire site over properly. I tried running the console in production mode on the server and couldn't find anything. Has anyone seen this before?
Since this path works in development and fails in production I would focus on the differences between your environments.
A common issue is that people commit their changes locally, but do not push them to (e.g.) GitHub before deploying with capistrano. Can you ssh into your server and go to the current path and run rake routes there? Try and check if there are differences.
Once you've confirmed that at least the routes on the server are up to date, try checking the production log while accessing /user/password/new. It should be in /shared/log/production.log. You could ssh there and use tail -f production.log to follow the log while you try to access the path.
On a side note, it seems that you are using Devise. There have been similar issues for the user root path. See for example this question. Perhaps this will shed some light on your problem.

Resources