Install Discourse on macOS for development

I’m having some issues with setting up discourse for development on my M1 Mac.

fast_xs and gc_tracer gems fail to install with almost similar errors. I’ve pasted the fast_xs error message below. Could someone help ?

Building native extensions. This could take a while...
ERROR:  Error installing fast_xs:
	ERROR: Failed to build gem native extension.

    current directory: /Users/sisirkoppaka/.gem/ruby/3.2.0/gems/fast_xs-0.8.0/ext/fast_xs
/Users/sisirkoppaka/.rubies/ruby-3.2.0/bin/ruby -I /Users/sisirkoppaka/.rubies/ruby-3.2.0/lib/ruby/site_ruby/3.2.0 extconf.rb
checking for assert.h... yes
creating Makefile

current directory: /Users/sisirkoppaka/.gem/ruby/3.2.0/gems/fast_xs-0.8.0/ext/fast_xs
make DESTDIR\= sitearchdir\=./.gem.20240203-10621-j9d0j7 sitelibdir\=./.gem.20240203-10621-j9d0j7 clean

current directory: /Users/sisirkoppaka/.gem/ruby/3.2.0/gems/fast_xs-0.8.0/ext/fast_xs
make DESTDIR\= sitearchdir\=./.gem.20240203-10621-j9d0j7 sitelibdir\=./.gem.20240203-10621-j9d0j7
compiling fast_xs.c
fast_xs.c:144:39: error: incompatible function pointer types passing 'VALUE (VALUE)' (aka 'unsigned long (unsigned long)') to parameter of type 'VALUE (*)(VALUE, VALUE)' (aka 'unsigned long (*)(unsigned long, unsigned long)') [-Wincompatible-function-pointer-types]
  144 |         array = rb_rescue(unpack_utf8, self, unpack_uchar, self);
      |                                              ^~~~~~~~~~~~
/Users/sisirkoppaka/.rubies/ruby-3.2.0/include/ruby-3.2.0/ruby/internal/iterator.h:364:62: note: passing argument to parameter 'r_proc' here
  364 | VALUE rb_rescue(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*r_proc)(VALUE, VALUE), VALUE data2);
      |                                                              ^
1 error generated.
make: *** [fast_xs.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/sisirkoppaka/.gem/ruby/3.2.0/gems/fast_xs-0.8.0 for inspection.
Results logged to /Users/sisirkoppaka/.gem/ruby/3.2.0/extensions/arm64-darwin-22/3.2.0-static/fast_xs-0.8.0/gem_make.out```

How was this resolved?

When executing

bundle exec rake db:create
bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate

after starting both Redis and Postgres servers I get the following error.

fe_sendauth: no password supplied
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!

When I do this without starting my Redis and Postgres servers I get the following error.

bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate
Couldn't connect to Redis
rake aborted!

Can someone tell me what to do, I am lost.

Thanks

So far I have managed to solve it with the following commands:

bundle config build.fast_xs --with-cflags=\"-Wno-incompatible-pointer-types\"
bundle config build.gc_tracer --with-cflags=\"-Wno-incompatible-pointer-types\"
bundle install

Note that we have decided to drop both of these non-essential gems in

and

3 Likes

After invoking this option, how does one then shut down the server?

This doesn’t seem to work (anymore), I am getting:

fatal: couldn't find remote ref master

Neither does the version to overwrite local changes (2 posts down).

Any ideas on how to upgrade a macOS Discourse Dev Install?

master was renamed to main a while ago. Try

cd ~/discourse
git pull origin main
4 Likes

Thanks Simon, that helps.

I was able to run the git command but somewhere along the way broke my development environment. I now ended up with a broken dev environment, it shows my Discourse dev homepage but nothing seems to work (New Topic keeps spinning).

What is the easiest way to do a reset or a clean install of my Discourse dev install?

I tried to rerun the install commands at the start of this topic (it breaks on the pnpm install command). I also tried to run rake db:drop db:create db:migrate proposed by Arpit earlier in this topic, no success either.

I was able to update my pnpm and node installs by running npm install -g pnpm and brew install node which allowed me to rerun the install instructions again. However I am now getting the following Build error:

Module not found: Error: Can't resolve '@ember/debug' in '/Users/pieces/discourse/app/assets/javascripts/node_modules/ember-tracked-storage-polyfill/addon/index.js'

Did you run pnpm install after running npm install -g pnpm?

Details about the change to using pnpm for package management are here: Discourse core is switching to pnpm for JS package management.

2 Likes

Yes I did, still getting the error.

I performed the following steps:

  1. I updated packages on my Mac (reran the initial script)
  2. Ran bundle install
  3. Ran pnpm install
  4. Ran bundle exec rake db:create bundle exec rake db:migrate RAILS_ENV=test bundle exec rake db:create db:migrate
  5. Ran bundle exec rails server
  6. Ran bin/ember-cli in a separate terminal window

Running step 6 throws the error.

Looking at the details from the link you provided it feels like the Yarn Managed Node modules are not properly converted to pnpm? It talks about manually removing the ‘node_modules’ folder. However, this should be taken care of with the new git pull, right?

Please see below the error from step 6.

The image displays a computer screen with a command-line interface in a terminal window.  (Captioned by AI)

I can share the mentioned error log if that will help find the cause.

It’s worth noting that I don’t have a macOS system to test this on. I recently updated my local instance of Discourse on an Arch Linux system though. I’d expect the way that javascript dependencies are handled to be similar on both systems.

I don’t think that is correct. The node_modules directory isn’t tracked by git. The node modules are installed when you run pnpm install.

I can’t guarantee this is correct, but if I was getting the error, I would remove and then reinstall the dependencies with:

rm -rf node_modules app/assets/javascripts/*/node_modules

pnpm install

I think ember-tracked-storage-polyfill is in the discourse/node_modules directly, but it should be safe to run the full command I posted above.

You could also try runing pnpm install with verbose logging if it returns errors:

pnpm install --reporter=silent --loglevel=verbose

I just removed and reinstalled the dependencies, the command provided worked fine. It removes and installs pnpm without errors.

However, when I run the bin/ember-cli it still gives the same error.

Is there a way to completely remove my Discourse dev install and do a clean pull from Git and run the install clean?

I am totally fine with losing the data from my dev environment.

You could run rm -rf ~/discourse to completely remove the Discourse source code. Then follow the install guide from its “Clone Discourse” step: Install Discourse on macOS for development.

2 Likes

That did it!

Thanks for your patience Simon, appreciate you not giving up :slight_smile:

2 Likes

Great! I’m guessing that the issue was related to cached assets that had previously been complied in the /discourse/tmp/cache/assets/sprockets/ directory. Possibly the issue could have been resolved by running:

rm -rf ~/discourse/tmp/cache/

This is just a guess though.

2 Likes