Re: Shopify CLI gives an Error while using it to create an extension!

Solved

Shopify CLI gives an Error while using it to create an extension!

Jeremy46
Shopify Partner
9 2 0

Hi

My name is jeremy . I'm rather new to using Shopify cli, and I've been trying to create a subscription app extension .

but after running "Shopify extension create" and choosing my app and extension name , the "initializing project" process stops with this error.(it doesnt give an error when creating other extensions)

pic.png

I've been looking everywhere for any sort of answer but I truly cant find what's causing this issue.

any idea's would be greatly appreciated 

thank you

Accepted Solution (1)
MaxNodland
Excursionist
14 1 6

This is an accepted solution.

Try changing shopify-cli\lib\project_types\extension\commands\serve.rb from:

      def find_available_port(runtime_configuration)
        return runtime_configuration unless specification_handler.choose_port?(@ctx)

        chosen_port = Tasks::ChooseNextAvailablePort
          .call(from: runtime_configuration.port)
          .unwrap { |_error| @ctx.abort(@ctx.message("serve.no_available_ports_found")) }
        runtime_configuration.tap { |c| c.port = chosen_port }
      end

to:

      def find_available_port(runtime_configuration)
        puts "Hack fix is in place."
        return runtime_configuration
      end

 

View solution in original post

Replies 14 (14)

Jeremy46
Shopify Partner
9 2 0

I need to clarify i was using these instructions that shopify has provided here. and im stuck on the first step

 

Jeremy46
Shopify Partner
9 2 0

Found it! the problem  was my node so i updated it and it works , but now when i run "shopify extension serve" i get the message:

X No available ports found to run extension.

 

MaxNodland
Excursionist
14 1 6

I'm running into the same problem with 'no available ports'. I'll post back here if I find a solution.

Jeremy46
Shopify Partner
9 2 0

oh thank you! ive been stuck on this for days

 

MaxNodland
Excursionist
14 1 6

I've found the problem - I think. At least it's working for me.

The Shopify CLI file 'choose_next_available_port.rb' method 'available' returns true or false depending on if the default port is open. To do this they try to open a socket for the port, and catch ECONNREFUSED errors. If the connection is refused the port is open, right? Well instead of throwing ECONNREFUSED I'm getting ETIMEDOUT, so it doesn't catch that, and Shopify CLI thinks the port is being used.

I've changed the rescue block to handle ETIMEDOUT instead of ECONNREFUSED and now it's working. This is on line 31 of the file 'choose_next_available_port.rb' in Shopify-CLI version 2.1.0

I got it working and it loads the Post Purchase extension successfully.

MaxNodland
Excursionist
14 1 6

See my PR on the Shopify-CLI GitHub for the exact code change: https://github.com/Shopify/shopify-cli/pull/1372

Jeremy46
Shopify Partner
9 2 0

thank you so much for the answer. i did the change and now though it takes longer but i still get the error. 

MaxNodland
Excursionist
14 1 6

Hmm strange. I wonder if it's throwing yet another error type and not the ECONNREFUSED or ETIMEDOUT.

You can edit the Shopify-CLI code to skip the port check if you know that ports open. It's clearly a hack-fix and only a temporary solution.

On line 47 of shopify-cli\lib\project_types\extension\commands\serve.rb

Replace 

      def find_available_port(runtime_configuration)
        return runtime_configuration unless specification_handler.choose_port?(@ctx)

        chosen_port = Tasks::ChooseNextAvailablePort
          .call(from: runtime_configuration.port)
          .unwrap { |_error| @ctx.abort(@ctx.message("serve.no_available_ports_found")) }
        runtime_configuration.tap { |c| c.port = chosen_port }
      end

 

with

      def find_available_port(runtime_configuration)
        puts 'Hack fix is in place.'
        return runtime_configuration
      end

 

If you've edited the correct file you should see "Hack fix is in place." in the terminal when you run 'shopify extension serve', and hopefully it works.

MaxNodland
Excursionist
14 1 6

This is an accepted solution.

Try changing shopify-cli\lib\project_types\extension\commands\serve.rb from:

      def find_available_port(runtime_configuration)
        return runtime_configuration unless specification_handler.choose_port?(@ctx)

        chosen_port = Tasks::ChooseNextAvailablePort
          .call(from: runtime_configuration.port)
          .unwrap { |_error| @ctx.abort(@ctx.message("serve.no_available_ports_found")) }
        runtime_configuration.tap { |c| c.port = chosen_port }
      end

to:

      def find_available_port(runtime_configuration)
        puts "Hack fix is in place."
        return runtime_configuration
      end

 

Octipus
Shopify Partner
30 2 7

this works well. 

I know it's a work around but would be nice to have an official fix as everytime i update Shopify CLI i need to edit this bit. 

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
Octipus
Shopify Partner
30 2 7

Can this be merged into github?

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
MaxNodland
Excursionist
14 1 6

Hmm, strange that the hack no longer works. It doesn't look like they've changed anything related in the serve.rb file.

I have a pull request out, but it's not been merged.

Also - I've since switched to a new dev computer and the problem has resolved itself. Both machines use Windows 10, etc... but the underlying problem has something to do with system configuration.

junaidjibran
Shopify Partner
2 0 0

guide me to find this file

MaxNodland
Excursionist
14 1 6

The file I changed is located at "C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\shopify-cli-2.1.0\lib\project_types\extension\commands\serve.rb" for me.

I'm on windows.

To find where your gems are installed run "gem env" in console and find GEM PATHS. For reference, my gem path is "C:/Ruby30-x64/lib/ruby/gems/3.0.0".

Also run "shopify version" in console and make sure you're updating the correct Shopify-CLI gem.