Angular CLI Upgrade 'Cannot find module' Error

Every couple months I try to upgrade to the latest version of the Angular CLI and every time I run into this error.

Cannot find module ‘webpack/lib/dependencies/ContextElementDependency’
Error: Cannot find module ‘webpack/lib/dependencies/ContextElementDependency’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\node_modules\@ngtools\webpack\src\plugin.js:8:34)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

Every time I realize I miss a step so I want to document the steps I ended using so I don’t have to search for the solution again.  All the steps below are recommended by the Angular CLI Upgrade page, except the highlighted step below that removes the package-lock.json file.

Global install upgrade
NPM will keep a globally installed version of the Angular CLI that will be used across the system. It is updated using these steps, which will uninstall the current version and then install the new version.

npm uninstall -g @angular/cli
npm cache verify
# if npm version is < 5 then use npm cache clean
npm install -g @angular/cli@latest

Local install upgrade
The Angular project itself will have its own version of the CLI installed in the node_modules folder of the project.  It is updated using these instructions, which will remove the node_modules directory, update the version of the dependency in package.json and then reinstalls all the dependencies.  

rm -rf node_modules dist
rm package-lock.json # deletes the package.json lock file
npm install –save-dev @angular/cli@latest
npm install

Heroku Database Problems

I have been using Heroku for over a year now and have learned quite a bit along the way. I have a very simple Java web application for my work softball team, TAP Softball. It uses a Postgres database and contains basic information like the teams, schedule and standings. The database connection is configured using Spring and Hibernate, with the database URL and credentials hard coded right into the Spring context file. Using Eclipse and the Tomcat plugin I can deploy the web application locally to test changes prior to deploying to the server. I also have a local database I use for testing database changes before pushing to the live database. In the Spring context file I have a commented out localhost datasource defined, which I swap in when testing locally.

Yesterday, I received an email from Heroku that my database was going to be upgraded with the latest Postgres changes. A few minutes later an email confirmed the upgrade finished successfully. I had seen these messages before and thought nothing of it until this morning when I tried to use the site and got a big fat stack trace.

It didn’t take long to see the database URL and credentials had changed, which as you probably figured out was problematic since I had them hard coded. I quickly scrambled to fix the issue because I didn’t have access to my MacBook. The Dropbox deployment method didn’t work so I installed the Heroku Toolbelt and was able to update the database connection information. The site was back online, so I took a breather and then emailed support to find out what was going on.

Support promptly responded to my message and explained that if an upgrade doesn’t go perfectly the database will move to a different address and reset the credentials. He also said I should be loading my database connection information from the environment variables, so it will start up correctly should the database move again. I did a little searching and found Connecting to Relational Databases on Heroku with Java. After scrolling down I quickly found that I had to add a new Spring bean that would instantiate a Java URI using the DATABASE_URL environment variable. I also had to update my existing dataSource bean to get the host, port, path, username and password from the URI bean. I pushed the change up to Heroku and it worked.

My next challenge was to get my development environment working again, because now Tomcat was getting a null pointer exception when trying to generate the URI bean. After some trial and error I figured out that I needed to modify the run configuration for the Tomcat server in Eclipse to have a new entry in the Environment tab for the DATABASE_URL. The value to use came from my app’s database page on the Heroku site, in the last item called URL. Making this change and starting the server loaded the homepage, but when I attempted to load a page that used the database I received an error about SSL.

I remembered having problems connecting to the database originally, and to fix it I added ?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory to the end of the path. Unfortunately just sticking that onto the end of my Run Configuration’s environment variable didn’t work. I also had to add + '?' + @dbUrl.getQuery() to the end of the url property in my datasource bean. In the URI the part after the question mark is called the query and by appending it to the end of the path it fixed my issue. I pushed the change up to the server and it still worked fine. The best part is now I can easily create separate run configurations for the remote and local databases rather than randomly updating one of my Spring configuration files.

Creative Opportunity Cost

On the last episode of Analog, #76 Well, I Drive a BMW , there was continuation of a previous discussion about creating a new fan community for Relay FM using Slack or some other tool for creating communities. Initially, I thought how much fun it would be seeing the various Relay FM hosts communicating with each other and also with fans. After listening to the entire discussion on the podcast and then thinking about it for a few days my opinion changed. A community would provide some new content and might allow me to interact with the hosts of the podcasts I listen to everday, but at what cost to those very podcasts and the hosts who have spread themselves out very thin across many different projects.

You have to look no further than Upgrade co-hosts, Myke Hurley and Jason Snell, to see an example of podcasting work horses with a lot on their plate. Mr. Hurley, co-founder of Relay FM, appears on at least 8 different podcasts and as far as I can tell handles the marketing and personnel for the network. Mr. Snell, founder and writer at Six Colors, runs The Incomparable podcast network and is a host on at least a half dozen podcasts across both networks. On top of all that work they are always replying to tweets, chatting on Slack and oh yeah, then having their regular lives too.

Asking them to also converse in special forums with fans will not only be more stuff on their plates, but it runs the risk of taking time away from projects which push the network and the medium forward. If given the choice I would much prefer Mr. Hurley work on another special series like Behind the App than see him rehash the same topic from a podcast in some chat room somewhere. The hosts only have a limited amount of time and creativity to work with and it shouldn’t be squandered.

My other concern is how the podcasts themselves may suffer if the hosts spend time disussing topics in a community forum. As soon as podcasts start referencing these online discussions during the podcast it is going to alienate any listeners who haven’t been following along online. Right now any tweets or feedback from listeners is always shared during the podcast and everybody is kept in the loop. I would also be concerned about the hosts getting burnt out on a topic from discussing in a community forum off air. Keeping these discussions mostly limited to podcasts helps keep them fresh.

It would be great to hear my favorite podcast hosts chatting away in some community forum, but not if it prevents them from working on new creative projects or improving their existing ventures. I would rather them focus on what they are great at and keep moving the podcast brain ball down the field.