gjaldon / heroku-buildpack-phoenix-static

A Heroku buildpack for building Phoenix's static assets
MIT License
229 stars 224 forks source link

Node version error #80

Closed BestLuke closed 5 years ago

BestLuke commented 5 years ago

Sorry if I am misjudging the issue but I will try and provide as much information as I can. -I have attempted to increase my node version through the buildpack to 10.10.0/8.11.2 as I have some nested javascript files that need to be running a higher version.(Being done through buildpacks config)

-When I push to Heroku and it does it's CI test's I get this error while in test setup

 cp: cannot overwrite directory '/tmp/cache050174931/node_modules/phoenix' with non-directory
 cp: cannot overwrite directory '/tmp/cache050174931/node_modules/phoenix_html' with non-directory

(which error's out the CI test) -This issue appears to be coming from within the install_and_cache_deps function of the lib/build.sh file

install_and_cache_deps() {
  info "Installing and caching node modules"
  cd $assets_dir
  if [ -d $cache_dir/node_modules ]; then
    mkdir -p node_modules
    cp -r $cache_dir/node_modules/* node_modules/
  fi

 if [ -f "$assets_dir/yarn.lock" ]; then
   install_yarn_deps
 else
   install_npm_deps
 fi

 cp -r node_modules $cache_dir
 PATH=$assets_dir/node_modules/.bin:$PATH
 install_bower_deps
}

-The code will make it through the first cp command of the app without complication but when it reaches time to do the second cp command this issue occurs.

Am I missing something obvious or is this an issue with the buildpack and current versions of node?

If you need any more information please let me know and thank you in advance for any help you can provide

yellow5 commented 5 years ago

I am receiving similar errors when I try deploying an app to heroku-18 stack:

cp: cannot overwrite directory '/app/tmp/cache/node_modules/phoenix' with non-directory
cp: cannot overwrite directory '/app/tmp/cache/node_modules/phoenix_html' with non-directory

My config also sets a recent node version:

# NodeJS version
node_version=10.15.1

# NPM version
npm_version=6.4.1

# Phoenix assets path
assets_path=assets

# Phoenix mix namespace
phoenix_ex=phx

@BestLuke were you able to find a work around?

yellow5 commented 5 years ago

Update

Adding this to the config file allowed a successful deploy:

# Clean out cache contents from previous deploys
clean_cache=true

After that, I set the value back to false and successfully deployed again.

There must be something about the previous cache that was colliding with the previous node version used. In my case, I was using the default of the buildback: v6.9.2

Hope that helps...

gjaldon commented 5 years ago

@BestLuke it looks like this issue was caused by phoenix and phoenix_html inside node_modules no longer being directories. cp can't overwrite directories with files. Changing the node version might have caused this or maybe updating the deps.

The only fix is to use clean_cache as @yellow5 pointed out.

jesseshieh commented 4 years ago

On gigalixir, we get customers asking about this issue almost every single day. I assume it is also happening frequently on Heroku. In fact, it's probably the single biggest issue we get regarding this buildpack. I wonder if there is a way to detect this scenario and fix it automatically. @gjaldon would you be willing to accept a pull request that fixes detects and auto-fixes this issue?

gjaldon commented 4 years ago

@jesseshieh I'd be happy to accept a PR to auto-detect and fix the issue.