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

Ruby 3 Windows 10 Gem load Error #365

Closed
Karoid opened this issue Dec 28, 2020 · 28 comments · Fixed by #373
Closed

Ruby 3 Windows 10 Gem load Error #365

Karoid opened this issue Dec 28, 2020 · 28 comments · Fixed by #373

Comments

@Karoid
Copy link

Karoid commented Dec 28, 2020

When I run 'rails s', I receive the following error:
D:/RubyInstaller/Ruby3.0.0/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi': AddDllDirectory failed for D:/RubyInstaller/Ruby3.0.0/lib/ruby/gems/3.0.0
/gems/pg-1.2.3/lib/x64-mingw32 (RubyInstaller::Runtime::DllDirectory::WinApiError)

It seems like there is some problem with gem installation process.

directory structure of pg gem installed in ruby 2.7:

image

directory structure of pg gem installed in ruby 3.0:

image

[Environment Details]
Ruby 3.0.0
Rails 6.1.0
Pg 1.2.3
PostgreSQL version: 10
OS: Windows10 (not WOL)

@charlie-prezzano
Copy link

I am running into the same issue.

I have installed Ruby-3.0.0 with RubyInstaller DevKit (Windows 10). The pg gem (v1.2.3) installs successfully, but when I start my local Rails App (in RubyMine, v 2020.3.1) I receive this error:
C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:69:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'pg'. (Bundler::GemRequireError)
Gem Load Error is: AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32

I did notice that pg gem (https://rubygems.org/gems/pg/versions/1.2.3-x64-mingw32) required ruby versions is listed as: >= 2.2, < 2.8.dev.

[Environment Details]
Ruby 3.0.0
Rails 5.2.4.4
Pg 1.2.3
PostgreSQL version: 12.5
OS: Windows10

@PsychoPhobic
Copy link

PsychoPhobic commented Jan 12, 2021

Hi, same issue here

Ruby 3.0.0
Rails 6.1.1
pg 1.2.3
windows 10

**this happens on rake db:create**
PS C:\Rails Projekte\ab 2020\pmaster> rake db:create
C:/Ruby30-x64/lib/ruby/3.0.0/ostruct.rb:110: warning: already initialized constant OpenStruct::VERSION
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ostruct-0.3.2/lib/ostruct.rb:110: warning: previous definition of VERSION was here
C:/Ruby30-x64/lib/ruby/3.0.0/ostruct.rb:336: warning: already initialized constant OpenStruct::InspectKey
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ostruct-0.3.2/lib/ostruct.rb:347: warning: previous definition of InspectKey was here
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'pg'.
Gem Load Error is: AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
Backtrace for gem load error is:
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'

C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'

Caused by:
RubyInstaller::Runtime::DllDirectory::WinApiError: AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
C:/Rails Projekte/ab 2020/pmaster/config/application.rb:7:in `<top (required)>'
C:/Rails Projekte/ab 2020/pmaster/Rakefile:4:in `require_relative'
C:/Rails Projekte/ab 2020/pmaster/Rakefile:4:in `<top (required)>'

Caused by:
LoadError: 126: Das angegebene Modul wurde nicht gefunden.   - C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so
C:/Rails Projekte/ab 2020/pmaster/config/application.rb:7:in `<top (required)>'
C:/Rails Projekte/ab 2020/pmaster/Rakefile:4:in `require_relative'
C:/Rails Projekte/ab 2020/pmaster/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
PS C:\Rails Projekte\ab 2020\pmaster>
**this happens on rails s**
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:69:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'pg'. (Bundler::GemRequireError)
Gem Load Error is: AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
Backtrace for gem load error is:
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require'
C:/Rails Projekte/ab 2020/pmaster/config/application.rb:7:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:138:in `block in perform'
<internal:kernel>:90:in `tap'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:135:in `perform'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command/base.rb:69:in `perform'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command.rb:50:in `invoke'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands.rb:18:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
bin/rails:4:in `<main>'
Bundler Error Backtrace:
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:65:in `block (2 levels) in require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require'
        from C:/Rails Projekte/ab 2020/pmaster/config/application.rb:7:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:138:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:135:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from bin/rails:4:in `<main>'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi': AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32 (RubyInstaller::Runtime::DllDirectory::WinApiError)
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require'
        from C:/Rails Projekte/ab 2020/pmaster/config/application.rb:7:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:138:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:135:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from bin/rails:4:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': 126: Das angegebene Modul wurde nicht gefunden.   - C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so (LoadError)
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:5:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require'
        from C:/Rails Projekte/ab 2020/pmaster/config/application.rb:7:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:138:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands/server/server_command.rb:135:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.1/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
        from bin/rails:4:in `<main>'

C:\Rails Projekte\ab 2020\pmaster>

@larskanis
Copy link
Collaborator

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

@francesco-loreti
Copy link

1. install postgresql per pacman: `ridk exec pacman -S mingw-w64-x86_64-postgresql` and reinstall pg gem
2. `set RUBY_DLL_PATH=<your-path-to-postgresql>/bin` as [in our CI](https://github.com/ged/ruby-pg/blob/4de2c7df34b23a23841b114ae6606161be44d269/appveyor.yml#L22) before running the ruby app.

Neither solution works for me.
pg-1.2.3-x64-mingw32 requires ruby version < 2.8.dev, >= 2.2, which is incompatible with the current version, ruby 3.0.0p0

@ryarturogi
Copy link

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

this worked but idk why looking for answers :/

@kalmenius
Copy link

@larskanis Any update on the Ruby 3.0 compatible gem updates? I'm in the same boat -- only downgrading Ruby seems to fix this on my Windows machine.

@francesco-loreti
Copy link

any news?

@cratag
Copy link

cratag commented Feb 25, 2021

I would like to know as soon as the gem is fixed

@PsychoPhobic
Copy link

it would be nice if someone could do something about the breaking bug. is it so difficult to build against a new version?
unfortunately i'm a hobby programmer and i can't fix it myself

@ariccio
Copy link

ariccio commented Mar 5, 2021

Something I'm noticing here is that rg.rb rescues a LoadError but rubyinstaller2 add_dll_directory raises a WinApiError.

Changing the rescue to a WinApiError causes the load to break somewhere entirely different:

C:\Users\Lucius Riccio\Documents\GitHub\COVID-CO2-tracker\COVID_CO2_TRACKER>rails credentials:edit
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- 3.0/pg_ext (LoadError)
Did you mean?  3.0.0/devkit
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2.1/lib/active_support/dependencies.rb:332:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:27:in `block in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:19:in `rescue in block in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:13:in `block in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler.rb:174:in `require'
        from C:/Users/Lucius Riccio/Documents/GitHub/COVID-CO2-tracker/COVID_CO2_TRACKER/config/application.rb:22:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command/actions.rb:22:in `require_application!'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/commands/credentials/credentials_command.rb:29:in `edit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from bin/rails:4:in `<main>'
C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi': AddDllDirectory failed for C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32 (LoadError)
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new'
        from C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler.rb:174:in `require'
        from C:/Users/Lucius Riccio/Documents/GitHub/COVID-CO2-tracker/COVID_CO2_TRACKER/config/application.rb:22:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command/actions.rb:22:in `require_application!'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/commands/credentials/credentials_command.rb:29:in `edit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from bin/rails:4:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': 126: The specified module could not be found.   - C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so (LoadError)
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2.1/lib/active_support/dependencies.rb:332:in `block in require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2.1/lib/active_support/dependencies.rb:299:in `load_dependency'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2.1/lib/active_support/dependencies.rb:332:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:5:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:61:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:61:in `block in require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:50:in `each'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler/runtime.rb:50:in `require'
        from C:/Ruby30-x64/lib/ruby/3.0.0/bundler.rb:174:in `require'
        from C:/Users/Lucius Riccio/Documents/GitHub/COVID-CO2-tracker/COVID_CO2_TRACKER/config/application.rb:22:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command/actions.rb:22:in `require_application!'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/commands/credentials/credentials_command.rb:29:in `edit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command/base.rb:69:in `perform'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/command.rb:50:in `invoke'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2.1/lib/rails/commands.rb:18:in `<main>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from bin/rails:4:in `<main>'

I suspect this is part of the problem, or at least a latent bug. It doesn't seem like the use of WinApiError is a recent change or anything.

@ariccio
Copy link

ariccio commented Mar 5, 2021

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

1 worked for me.

larskanis added a commit to larskanis/ruby-pg that referenced this issue Mar 16, 2021
... and add it to the search paths on Windows which lacks rpath.

In ELF based systems the libpq path is stored as rpath in pg_ext.so, so that libpq is found, even if it's not in the library search paths.

On Windows however the rpath mechanism doesn't work and the search path for libpq must be added manually.
This is done per RubyInstaller::Runtime.add_dll_directory.

The libpq path is available in extconf.rb while build only (while gem install), so that we have to pass the string to lib/pg.rb where pg_ext.so is loaded (while require 'pg').
This is a bit tricky, since pg_ext.so is linked to libpq, so that the library search path has to be set first, prior to loading pg_ext.so.
Therefore a second file is needed bypassing pg_ext.so.
That is postgresql_lib_path.rb and it is passed by mkmf's $INSTALLFILES mechanism.

There's an issue with rake-compiler, which (in contrast to gem install) doesn't copy postgresql_lib_path.rb.
This has to be addressed separatelly.

Another approach would be to add a second extension file, but that is more complicated.

Fixes ged#365
larskanis added a commit to larskanis/ruby-pg that referenced this issue Mar 19, 2021
... and add it to the search paths on Windows which lacks rpath.

In ELF based systems the libpq path is stored as rpath in pg_ext.so, so that libpq is found, even if it's not in the library search paths.

On Windows however the rpath mechanism doesn't work and the search path for libpq must be added manually.
This is done per RubyInstaller::Runtime.add_dll_directory.

The libpq path is available in extconf.rb while build only (while gem install), so that we have to pass the string to lib/pg.rb where pg_ext.so is loaded (while require 'pg').
This is a bit tricky, since pg_ext.so is linked to libpq, so that the library search path has to be set first, prior to loading pg_ext.so.
Therefore a second file is needed bypassing pg_ext.so.
That is postgresql_lib_path.rb and it is passed by mkmf's $INSTALLFILES mechanism.

There's an issue with rake-compiler, which (in contrast to gem install) doesn't copy postgresql_lib_path.rb.
This has to be addressed separatelly.

Another approach would be to add a second extension file, but that is more complicated.

Fixes ged#365
larskanis added a commit to larskanis/ruby-pg that referenced this issue Mar 19, 2021
... and add it to the search paths on Windows which lacks rpath.

In ELF based systems the libpq path is stored as rpath in pg_ext.so, so that libpq is found, even if it's not in the library search paths.

On Windows however the rpath mechanism doesn't work and the search path for libpq must be added manually.
This is done per RubyInstaller::Runtime.add_dll_directory.

The libpq path is available in extconf.rb while build only (while gem install), so that we have to pass the string to lib/pg.rb where pg_ext.so is loaded (while require 'pg').
This is a bit tricky, since pg_ext.so is linked to libpq, so that the library search path has to be set first, prior to loading pg_ext.so.
Therefore a second file is needed bypassing pg_ext.so.
That is postgresql_lib_path.rb and it is passed by mkmf's $INSTALLFILES mechanism.

There's an issue with rake-compiler, which (in contrast to gem install) doesn't copy postgresql_lib_path.rb.
This has to be addressed separatelly.

Another approach would be to add a second extension file, but that is more complicated.

Fixes ged#365
@francesco-loreti
Copy link

1. install postgresql per pacman: `ridk exec pacman -S mingw-w64-x86_64-postgresql` and reinstall pg gem

I'm not understand... One month ago this procedure not has been worked for me and now it's work. I'm happy :D

@rockwellll
Copy link

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem

Im getting this error running the command

error: failed to init transaction (unable to lock database)
error: could not lock database: File exists
  if you're sure a package manager is not already
  running, you can remove /var/lib/pacman/db.lck

@ajayKomirishetty
Copy link

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

step-1 worked for me. Thanks

@petudeveloper
Copy link

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

Thanks so much! this worked for me in 2021.

@starrychloe
Copy link

starrychloe commented Sep 20, 2021

This is not just Windows 10. This also happen on Windows 8.1. It happen during making the gem. gem install pg will work, but starting the console rails console will crash. When inside the gem, trying to make it works but the tests fail because it won't load. I don't want to use PacMan. I want to use Chocolatey to install Postgres (which is what I've done). pg_config works and is on the path. The pg_ext.so library file is there and exists. I'm using Ruby 3.

C:\ruby30\lib\ruby\gems\3.0.0\gems\pg-1.2.3>rake
DEPRECATED: I want to drop this entirely. Let me know if you use this! from C:/ruby30/lib/ruby/gems/3.0.0/gems/hoe-3.23.0/lib/hoe/test.rb:139:in `define_test_tasks'
mkdir -p tmp/x64-mingw32/pg_ext/3.0.2
cd tmp/x64-mingw32/pg_ext/3.0.2
C:/ruby30/bin/ruby.exe -I. ../../../../ext/extconf.rb
checking for pg_config... yes
Using config values from C:\Program Files\PostgreSQL\9.6\bin/pg_config.exe
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for workaround gcc version with link issue... yes
checking for PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for PQsslAttribute()... yes
checking for PQresultVerboseErrorMessage()... yes
checking for PQencryptPasswordConn()... no
checking for PQresultMemorySize()... no
checking for timegm()... no
checking for rb_gc_adjust_memory_usage()... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile
cd -
cd tmp/x64-mingw32/pg_ext/3.0.2
C:\msys64\usr\bin/make.exe
generating pg_ext-x64-mingw32.def
compiling ../../../../ext/gvl_wrappers.c
compiling ../../../../ext/pg.c
compiling ../../../../ext/pg_binary_decoder.c
compiling ../../../../ext/pg_binary_encoder.c
compiling ../../../../ext/pg_coder.c
compiling ../../../../ext/pg_connection.c
compiling ../../../../ext/pg_copy_coder.c
compiling ../../../../ext/pg_errors.c
compiling ../../../../ext/pg_record_coder.c
compiling ../../../../ext/pg_result.c
../../../../ext/pg_result.c: In function 'init_pg_result':
../../../../ext/pg_result.c:1590:2: warning: 'rb_cData' is deprecated: by: rb_cObject.  Will be removed in 3.1. [-Wdeprecated-declarations]
 1590 |  rb_cPGresult = rb_define_class_under( rb_mPG, "Result", rb_cData );
      |  ^~~~~~~~~~~~
In file included from C:/ruby30/include/ruby-3.0.0/ruby/internal/core.h:27,
                 from C:/ruby30/include/ruby-3.0.0/ruby/ruby.h:26,
                 from C:/ruby30/include/ruby-3.0.0/ruby.h:38,
                 from ../../../../ext/pg.h:20,
                 from ../../../../ext/pg_result.c:7:
C:/ruby30/include/ruby-3.0.0/ruby/internal/core/rdata.h:169:1: note: declared here
  169 | rb_cData(void)
      | ^~~~~~~~
compiling ../../../../ext/pg_text_decoder.c
compiling ../../../../ext/pg_text_encoder.c
compiling ../../../../ext/pg_tuple.c
compiling ../../../../ext/pg_type_map.c
compiling ../../../../ext/pg_type_map_all_strings.c
compiling ../../../../ext/pg_type_map_by_class.c
compiling ../../../../ext/pg_type_map_by_column.c
compiling ../../../../ext/pg_type_map_by_mri_type.c
compiling ../../../../ext/pg_type_map_by_oid.c
compiling ../../../../ext/pg_type_map_in_ruby.c
compiling ../../../../ext/pg_util.c
linking shared-object pg_ext.so
cd -
mkdir -p tmp/x64-mingw32/stage/lib
cp .gemtest tmp/x64-mingw32/stage/.gemtest
cp BSDL tmp/x64-mingw32/stage/BSDL
cp ChangeLog tmp/x64-mingw32/stage/ChangeLog
cp Contributors.rdoc tmp/x64-mingw32/stage/Contributors.rdoc
cp History.rdoc tmp/x64-mingw32/stage/History.rdoc
cp LICENSE tmp/x64-mingw32/stage/LICENSE
cp Manifest.txt tmp/x64-mingw32/stage/Manifest.txt
cp POSTGRES tmp/x64-mingw32/stage/POSTGRES
cp README-OS_X.rdoc tmp/x64-mingw32/stage/README-OS_X.rdoc
cp README-Windows.rdoc tmp/x64-mingw32/stage/README-Windows.rdoc
cp README.ja.rdoc tmp/x64-mingw32/stage/README.ja.rdoc
cp README.rdoc tmp/x64-mingw32/stage/README.rdoc
cp Rakefile tmp/x64-mingw32/stage/Rakefile
cp Rakefile.cross tmp/x64-mingw32/stage/Rakefile.cross
mkdir -p tmp/x64-mingw32/stage/ext
cp ext/errorcodes.def tmp/x64-mingw32/stage/ext/errorcodes.def
cp ext/errorcodes.rb tmp/x64-mingw32/stage/ext/errorcodes.rb
cp ext/errorcodes.txt tmp/x64-mingw32/stage/ext/errorcodes.txt
cp ext/extconf.rb tmp/x64-mingw32/stage/ext/extconf.rb
cp ext/gvl_wrappers.c tmp/x64-mingw32/stage/ext/gvl_wrappers.c
cp ext/gvl_wrappers.h tmp/x64-mingw32/stage/ext/gvl_wrappers.h
cp ext/pg.c tmp/x64-mingw32/stage/ext/pg.c
cp ext/pg.h tmp/x64-mingw32/stage/ext/pg.h
cp ext/pg_binary_decoder.c tmp/x64-mingw32/stage/ext/pg_binary_decoder.c
cp ext/pg_binary_encoder.c tmp/x64-mingw32/stage/ext/pg_binary_encoder.c
cp ext/pg_coder.c tmp/x64-mingw32/stage/ext/pg_coder.c
cp ext/pg_connection.c tmp/x64-mingw32/stage/ext/pg_connection.c
cp ext/pg_copy_coder.c tmp/x64-mingw32/stage/ext/pg_copy_coder.c
cp ext/pg_errors.c tmp/x64-mingw32/stage/ext/pg_errors.c
cp ext/pg_record_coder.c tmp/x64-mingw32/stage/ext/pg_record_coder.c
cp ext/pg_result.c tmp/x64-mingw32/stage/ext/pg_result.c
cp ext/pg_text_decoder.c tmp/x64-mingw32/stage/ext/pg_text_decoder.c
cp ext/pg_text_encoder.c tmp/x64-mingw32/stage/ext/pg_text_encoder.c
cp ext/pg_tuple.c tmp/x64-mingw32/stage/ext/pg_tuple.c
cp ext/pg_type_map.c tmp/x64-mingw32/stage/ext/pg_type_map.c
cp ext/pg_type_map_all_strings.c tmp/x64-mingw32/stage/ext/pg_type_map_all_strings.c
cp ext/pg_type_map_by_class.c tmp/x64-mingw32/stage/ext/pg_type_map_by_class.c
cp ext/pg_type_map_by_column.c tmp/x64-mingw32/stage/ext/pg_type_map_by_column.c
cp ext/pg_type_map_by_mri_type.c tmp/x64-mingw32/stage/ext/pg_type_map_by_mri_type.c
cp ext/pg_type_map_by_oid.c tmp/x64-mingw32/stage/ext/pg_type_map_by_oid.c
cp ext/pg_type_map_in_ruby.c tmp/x64-mingw32/stage/ext/pg_type_map_in_ruby.c
cp ext/pg_util.c tmp/x64-mingw32/stage/ext/pg_util.c
cp ext/pg_util.h tmp/x64-mingw32/stage/ext/pg_util.h
mkdir -p tmp/x64-mingw32/stage/ext/vc
cp ext/vc/pg.sln tmp/x64-mingw32/stage/ext/vc/pg.sln
mkdir -p tmp/x64-mingw32/stage/ext/vc/pg_18
cp ext/vc/pg_18/pg.vcproj tmp/x64-mingw32/stage/ext/vc/pg_18/pg.vcproj
mkdir -p tmp/x64-mingw32/stage/ext/vc/pg_19
cp ext/vc/pg_19/pg_19.vcproj tmp/x64-mingw32/stage/ext/vc/pg_19/pg_19.vcproj
cp lib/pg.rb tmp/x64-mingw32/stage/lib/pg.rb
mkdir -p tmp/x64-mingw32/stage/lib/pg
cp lib/pg/basic_type_mapping.rb tmp/x64-mingw32/stage/lib/pg/basic_type_mapping.rb
cp lib/pg/binary_decoder.rb tmp/x64-mingw32/stage/lib/pg/binary_decoder.rb
cp lib/pg/coder.rb tmp/x64-mingw32/stage/lib/pg/coder.rb
cp lib/pg/connection.rb tmp/x64-mingw32/stage/lib/pg/connection.rb
cp lib/pg/constants.rb tmp/x64-mingw32/stage/lib/pg/constants.rb
cp lib/pg/exceptions.rb tmp/x64-mingw32/stage/lib/pg/exceptions.rb
cp lib/pg/result.rb tmp/x64-mingw32/stage/lib/pg/result.rb
cp lib/pg/text_decoder.rb tmp/x64-mingw32/stage/lib/pg/text_decoder.rb
cp lib/pg/text_encoder.rb tmp/x64-mingw32/stage/lib/pg/text_encoder.rb
cp lib/pg/tuple.rb tmp/x64-mingw32/stage/lib/pg/tuple.rb
cp lib/pg/type_map_by_column.rb tmp/x64-mingw32/stage/lib/pg/type_map_by_column.rb
mkdir -p tmp/x64-mingw32/stage/spec/data
cp spec/data/expected_trace.out tmp/x64-mingw32/stage/spec/data/expected_trace.out
cp spec/data/random_binary_data tmp/x64-mingw32/stage/spec/data/random_binary_data
cp spec/helpers.rb tmp/x64-mingw32/stage/spec/helpers.rb
mkdir -p tmp/x64-mingw32/stage/spec/pg
cp spec/pg/basic_type_mapping_spec.rb tmp/x64-mingw32/stage/spec/pg/basic_type_mapping_spec.rb
cp spec/pg/connection_spec.rb tmp/x64-mingw32/stage/spec/pg/connection_spec.rb
cp spec/pg/connection_sync_spec.rb tmp/x64-mingw32/stage/spec/pg/connection_sync_spec.rb
cp spec/pg/result_spec.rb tmp/x64-mingw32/stage/spec/pg/result_spec.rb
cp spec/pg/tuple_spec.rb tmp/x64-mingw32/stage/spec/pg/tuple_spec.rb
cp spec/pg/type_map_by_class_spec.rb tmp/x64-mingw32/stage/spec/pg/type_map_by_class_spec.rb
cp spec/pg/type_map_by_column_spec.rb tmp/x64-mingw32/stage/spec/pg/type_map_by_column_spec.rb
cp spec/pg/type_map_by_mri_type_spec.rb tmp/x64-mingw32/stage/spec/pg/type_map_by_mri_type_spec.rb
cp spec/pg/type_map_by_oid_spec.rb tmp/x64-mingw32/stage/spec/pg/type_map_by_oid_spec.rb
cp spec/pg/type_map_in_ruby_spec.rb tmp/x64-mingw32/stage/spec/pg/type_map_in_ruby_spec.rb
cp spec/pg/type_map_spec.rb tmp/x64-mingw32/stage/spec/pg/type_map_spec.rb
cp spec/pg/type_spec.rb tmp/x64-mingw32/stage/spec/pg/type_spec.rb
cp spec/pg_spec.rb tmp/x64-mingw32/stage/spec/pg_spec.rb
install -c tmp/x64-mingw32/pg_ext/3.0.2/pg_ext.so lib/pg_ext.so
cp tmp/x64-mingw32/pg_ext/3.0.2/pg_ext.so tmp/x64-mingw32/stage/lib/pg_ext.so
C:/ruby30/bin/ruby.exe -I'C:/ruby30/lib/ruby/gems/3.0.0/gems/rspec-support-3.9.4/lib';'C:/ruby30/lib/ruby/gems/3.0.0/gems/rspec-core-3.9.3/lib' 'C:/ruby30/lib/ruby/gems/3.0.0/gems/rspec-core-3.9.3/exe/rspec' --pattern 'spec/**{,/*/**}/*_spec.rb' -Ispec:lib

An error occurred while loading ./spec/pg/basic_type_mapping_spec.rb. - Did you mean?
                    rspec ./spec/pg/type_map_by_class_spec.rb

Failure/Error: require 'rspec'

LoadError:
  cannot load such file -- rspec
# ./spec/helpers.rb:4:in `<top (required)>'
# ./spec/pg/basic_type_mapping_spec.rb:4:in `require_relative'
# ./spec/pg/basic_type_mapping_spec.rb:4:in `<top (required)>'

... many more RSpec errors ... Here is the critical error:

An error occurred while loading ./spec/pg/type_spec.rb.
Failure/Error: RubyInstaller::Runtime.add_dll_directory(path, &block)

RubyInstaller::Runtime::DllDirectory::WinApiError:
  AddDllDirectory failed for C:/ruby30/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
# ./lib/pg.rb:15:in `block in <top (required)>'
# ./lib/pg.rb:26:in `rescue in <top (required)>'
# ./lib/pg.rb:4:in `<top (required)>'
# ./spec/pg/type_spec.rb:4:in `<top (required)>'
# ------------------
# --- Caused by: ---
# LoadError:
#   126: The specified module could not be found.   - C:/ruby30/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so
#   ./lib/pg.rb:5:in `<top (required)>'

The file exists:

C:\ruby30\lib\ruby\gems\3.0.0\gems\pg-1.2.3>ls -l C:/ruby30/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so
-rwxr-xr-x 1 Chloe None 236544 Sep 20 11:13 C:/ruby30/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so

I'm following the instructions for Windows: https://github.com/ged/ruby-pg/blob/master/README-Windows.rdoc

In order to build ruby-pg, just run 'rake'.

Setting the RUBY_DLL_PATH does not help.

C:\ruby30\lib\ruby\gems\3.0.0\gems\pg-1.2.3>set RUBY_DLL_PATH="\Program Files\PostgreSQL\9.6\bin"

C:\ruby30\lib\ruby\gems\3.0.0\gems\pg-1.2.3>echo %RUBY_DLL_PATH%
"\Program Files\PostgreSQL\9.6\bin"

C:\ruby30\lib\ruby\gems\3.0.0\gems\pg-1.2.3>rspec
[...]
An error occurred while loading ./spec/pg/type_spec.rb.
Failure/Error: RubyInstaller::Runtime.add_dll_directory(path, &block)

RubyInstaller::Runtime::DllDirectory::WinApiError:
  AddDllDirectory failed for C:/ruby30/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
# ./lib/pg.rb:15:in `block in <top (required)>'
# ./lib/pg.rb:26:in `rescue in <top (required)>'
# ./lib/pg.rb:4:in `<top (required)>'
# ./spec/pg/type_spec.rb:4:in `<top (required)>'
# ------------------
# --- Caused by: ---
# LoadError:
#   126: The specified module could not be found.   - C:/ruby30/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so
#   ./lib/pg.rb:5:in `<top (required)>'

@starrychloe
Copy link

Oh my. This did work. I could have sworn I had rspec installed because the binary was in my path.

C:\ruby30\lib\ruby\gems\3.0.0\gems\pg-1.2.3>which rspec
/c/ruby30/bin/rspec

This did work (without the quotes around the path):

gem install rspec
...
set RUBY_DLL_PATH=\Program Files\PostgreSQL\9.6\bin
rspec
...
Finished in 3 minutes 4.8 seconds (files took 2.88 seconds to load)
681 examples, 0 failures, 2 pending

@RyanB1303
Copy link

1. install postgresql per pacman: `ridk exec pacman -S mingw-w64-x86_64-postgresql` and reinstall pg gem

this solution works for me, on ruby 3.0.2, windows 10, postgresql 13

@Vandreh
Copy link

Vandreh commented Nov 11, 2021

I had a similar problem in Windows 11 with Command Prompt, but I solved the problem by simply opening Git Bash in the VSCODE terminal and executing the commands

@ZzZombo
Copy link

ZzZombo commented Dec 12, 2021

Nothing has ever worked for me. Such a bummer, any news on this issue? It's been a few years since it first started.

@larskanis
Copy link
Collaborator

pg-1.3.0 is released, adding support for ruby-3.0 and 3.1 on Windows to the fat binary gems. Sorry for the long delay!

@stomar
Copy link

stomar commented Jan 24, 2022

Thanks!!! ❤️ Works like a charm.

@7MinutesDead-Git
Copy link

Let's go! Nice job

@clarestaoctavia
Copy link

i still have this trouble.. i've tried the ridk exec pacman -S mingw-w64-x86_64-postgresql, its said that command not found. I can't even use gem install bundle because it's said

ERROR: Could not find a valid gem 'bundle' (>= 0) in any repository

I am so lost by this, since my ruby and rails installation seems to works fine

@ariccio
Copy link

ariccio commented Apr 6, 2022

I can't even use gem install bundle because it's said

It happens to all of us, even the best of us :)

https://github.com/will/bundle

Try gem install bundler

@jake-007
Copy link

jake-007 commented Jan 9, 2024

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

Three years and three minor Ruby versions later and I got bitten by this, too. Nb. 1. was the solution, thank you!

Ruby 3.3.0, postgres installed locally. Installing the pg 1.5.2. x64-mingw-ucrt gem gave that "module not found" error. Had to remove the gem, download and install msys2 package x64-ucrt-postgresql and all its dependencies and then the pg gem.

@bdrazhzhov
Copy link

Ruby 3.3.0, postgres installed locally. Installing the pg 1.5.2. x64-mingw-ucrt gem gave that "module not found" error. Had to remove the gem, download and install msys2 package x64-ucrt-postgresql and all its dependencies and then the pg gem.

Thanks a lot. It's fixed for me:

  1. Installed mingw-w64-ucrt-x86_64-postgresql (.\ridk.cmd exec pacman -Sy mingw-w64-ucrt-x86_64-postgresql)
  2. gem install pg

@SimonKaluza
Copy link

This happens, if pg gem is installed with a dedicated PostgreSQL installation. I'll update the pg gem soon to fix this and to distribute ruby-3.0 compatible binary gems, but until then there are 3 workarounds:

  1. install postgresql per pacman: ridk exec pacman -S mingw-w64-x86_64-postgresql and reinstall pg gem
  2. set RUBY_DLL_PATH=<your-path-to-postgresql>/bin as in our CI before running the ruby app.
  3. Downgrade to ruby < 3.0, since that installs the binary windows gems instead.

This was very helpful, but keep in mind that command is specific for x86_64, which even on an 86_64 processor this may not be the right architecture for your Ruby install. If you're still having issues be sure to use the more generic command:

ridk exec sh -c "pacman -S ${MINGW_PACKAGE_PREFIX}-postgresql"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet