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

Solved
Jeremy46
Tourist
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)

Accepted Solutions
MaxNodland
Excursionist
14 1 5

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
Tourist
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
Tourist
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 5

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

Jeremy46
Tourist
9 2 0

oh thank you! ive been stuck on this for days

 

MaxNodland
Excursionist
14 1 5

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 5

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

Jeremy46
Tourist
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 5

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 5

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