tzinfo-data issue when starting new rails project
Managed to resolved the issue.
Steps:
1. Remove ", platforms: [:mingw, :mswin, :x64_mingw, :jruby]" in Gemfile for "gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]"
2. Run gem uninstall tzinfo-data
3. Run bundle install
After reinstalling back tzinfo-data, the rails server is able to start up.
Thank you for suggestions and effort to try and help me to resolve this issue.
failed to build rails server cause of tzinfo
There's a bug in Bundler that means there's no valid platform value that will match 64-bit Ruby 3.1 on Windows.
If the gem 'tzinfo-data
line in your Gemfile
includes a platforms
option, Bundler will exclude tzinfo-data from the bundle and you'll get the TZInfo::DataSourceNotFound
error.
The solution is to remove the platforms
option from the tzinfo-data line in the Gemfile and then run bundle install
:
gem 'tzinfo-data'
TZInfo::DataSourceNotFound error starting Rails v4.1.0 server on Windows
Resolving the Error
To resolve this error, you'll need to make sure that the tzinfo-data gem is being included in your Gemfile
.
First of all, check your Gemfile
to see if there is an existing reference to tzinfo-data
. If there isn't already a reference, then add the following line:
gem 'tzinfo-data'
You may find that there is already a line like the following:
gem 'tzinfo-data', platforms: [:mingw, :mswin]
If you are using a 64-bit version of Ruby on Windows, then add :x64_mingw
to the list of platforms as follows:
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
Alternatively, you can remove the platforms
option altogether.
Note that there is a bug in Bundler that means there's currently no platform option that will match 64-bit Ruby 3.1 on Windows. The solution here to remove the platforms
option.
After doing this, run bundle update
at the command line to install the tzinfo-data gem and you'll then be able to start your Rails server or console.
Background
The TZInfo::DataSourceNotFound
error is being raised by TZInfo, a dependency of the Active Support component of Rails. TZInfo is looking for a source of time zone data on your system, but failing to find one.
On many Unix-based systems (e.g. Linux), TZInfo is able to use the system zoneinfo directory as a source of data. However, Windows doesn't include such a directory, so the tzinfo-data gem needs to be installed instead. The tzinfo-data gem contains the same zoneinfo data, packaged as a set of Ruby modules.
Rails generates a default Gemfile
when the application is first created. If the application is created on Windows, then a dependency for tzinfo-data will be included. However Rails (up to version 4.1.x) omitted :x64_mingw
from the list of platforms and therefore didn't work correctly on 64-bit Windows versions of Ruby.
Related Topics
How to Debug Http of Ruby Google-Api-Client
How to Use Same Terminal Window After Using "Rails Server" Command
Passing a Hash to a Function ( *Args ) and Its Meaning
Raise Custom Exception with Arguments
Engine's Assets with Rails 3.1
How to Access Url Helper from Rails Module
Nicely Formatting Output to Console, Specifying Number of Tabs
Rspec 3 How to Test Flash Messages
How to Get the Parent's Class Name in Ruby
How to Call Java API from Ruby 1.8 or 1.9
How to Ruby on Rails Authentication with Ldap
Factory Girl - What's the Purpose
Ruby: Is There an Opposite of Include? for Ruby Arrays
Install Latest Stable Version of Ruby Using Rbenv
How to Calculate the Offset, in Hours, of a Given Timezone from Utc in Ruby