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

Could not find current hash key in config. #15

Open
warmwhisky opened this issue Nov 29, 2018 · 8 comments
Open

Could not find current hash key in config. #15

warmwhisky opened this issue Nov 29, 2018 · 8 comments

Comments

@warmwhisky
Copy link

When I run php artisan assetcachebuster:generate I get the following error.
Could not find current hash key in config.

@warmwhisky
Copy link
Author

I managed to get this working by deleting the config then running php artisan vendor:publish --provider="Spekkionu\Assetcachebuster\AssetcachebusterServiceProvider" --tag=config

Then php artisan assetcachebuster:generate worked again

@spekkionu
Copy link
Owner

Likely what happened is the content of your config file changed so that the replacer script could not find the part with your current hash to replace it. It might have event been something as simple as the file being formatted differently.

@warmwhisky
Copy link
Author

This happens every time I try to reset the cache. Now the above solution is not working.

@spekkionu
Copy link
Owner

Can you post the contents of your assetcachebuster.php config file?

@spekkionu spekkionu reopened this Jun 14, 2019
@warmwhisky
Copy link
Author

warmwhisky commented Jun 14, 2019

return array(

/*
|--------------------------------------------------------------------------
| Asset Cache Enabled
|--------------------------------------------------------------------------
|
| If this is set to true the asset urls will be prefixed with a hash to allow
| for cache invalidation.
|
| Setting this to false will not prefix urls with the hash effectively disabling
| the package.  This can be helpful to not use the hash prefix for development
| environments.
|
| Asset urls will still be prefixed with the cdn url.  This setting has no effect
| on that.
|
*/

'enable' => true,

/*
|--------------------------------------------------------------------------
| Asset Cache Prefix Hash
|--------------------------------------------------------------------------
|
| Asset urls will be prefixed with this hash for browser cache busting.
| This allows a long expires header to be set for asset files while
| still providing an easy way to force download of new versions of files.
|
| Change this hash to invalidate asset caches.
| It must be a 32 character string with only the characters 0-9 and a-f
| or the rewrite rule will need to be modified to match the used pattern.
|
| If set to null urls will not be rewritten effectively disabling the package.
|
| You can run "php artisan assetcachebuster:generate" to automatically generate
| a new hash.
|
*/

'hash' => '96c8a2176fd1f379e91e512e1418b94e',

/*
|--------------------------------------------------------------------------
| Asset Path Prefix
|--------------------------------------------------------------------------
|
| If all of the assets you want cached are in a directory you may limit
| the caching to only that directory.
|
| If this is set you must also modify the rewrite rule.
| For example if your assets are all inside a directory named "assets"
| Set this value to "assets" and modify the rewrite rule to
| RewriteRule ^assets/[a-f0-9]{32}/(.*)$ assets/$1 [L]
|
| You can also prefix urls to avoid clashes with any laravel routes.
| For example if you have a route that begins with a md5 hash
| this package will prevent that route from working normally.
| To get around this set this prefix to a unique value that wont appear
| in any of your routes.
| Say you want to use the prefix cachedasset
| Set the rewrite rule to the following
| RewriteRule ^cachedasset/[a-f0-9]{32}/(.*)$ $1 [L]
|
*/
'prefix' => null,


/*
|--------------------------------------------------------------------------
| CDN URL
|--------------------------------------------------------------------------
|
| The cdn url.
| If null no cdn will be used.
|
*/
'cdn' => null,

Edit: changed to enable true as I had to disable it to get my css to work

@spekkionu
Copy link
Owner

The generation of the new hash seems to work with your config file on my install.

What version of this package are you using?
What version of Laravel are you using?
What version of php are you running?
What OS are you trying to run the command on?

@warmwhisky
Copy link
Author

Sorry for the lask of info.
Package: "spekkionu/assetcachebuster": "3.*"
Laravel: 5.5
PHP: 7.1.11
OS: Windows 7

Though I have the same problem when I run this on my Centos 6 server.

@gogromat
Copy link

gogromat commented Mar 2, 2021

Another solution is to modify an exception in ConfigHashReplacer::writeHash to display current hash: throw new \RuntimeException(" ... {$currentHash}");

Change assetcachebuster.php's 'hash' => '...' to match $currentHash value.

After that running php artisan assetcachebuster:generate would regex-match current hash in assetcachebuster.php config file and will succeed with generating a new hash.

This issue happens because php artisan config:cache remembers assetcachebuster.php's 'hash' (into config.php), but if it does not match current assetcachebuster.php's hash, this error will remain.
So if you are caching your config, make sure to call php artisan config:cache right after php artisan assetcachebuster:generate in order to propogate newly generated hash into a cached config file.

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

No branches or pull requests

3 participants