<p>Because your <code>FooBundle</code> has the classname <code>MyPluginAsset</code>rename your class to <code>FooBundle</code> and it should work (if your namespace is correct, since your information are not really detailed as always)</p>

<p>The docs are not supposed to be a place for copy paste but a source for information. </p>

CC BY-SA 4.0
2018-05-06T14:06:44.493Z
OK. So it is a namespace/classname error. Thanks for the pointer in the right direction. Namespaces are new to me. My last PHP work was in 4.x.
Eric Snyder
CC BY-SA 4.0
2018-05-06T14:06:58.753Z
"The docs are not supposed to be a place for copy paste but a source for information.". Yep, I understand. I am still learning/rebuilding my knowledge after being out of PHP a long time. I'm really sorry for my lack of knowledge. I appreciate your patience and willingness to share and help.
Eric Snyder
CC BY-SA 4.0
2018-05-06T19:28:45.987Z
It's not your fault. Craft docs are not that good. Some things are well explained there (that's why I always refer to those) and many questions here can be solved by looking in the documentation but for most things it's better/easier to look at yii2 instead of Craft
Robin Schambach
CC BY-SA 4.0
2020-06-05T12:46:01.580Z
I had the same problem, but I corrected the namespace, the name of the file I had changed already. But I am still facing the same error. :(
Rohan
CC BY-SA 4.0
2018-05-06T05:58:51.967Z
2018-05-06T06:04:14.077Z
2018-05-06T06:04:14.077Z
Robin Schambach
<p>I have searched for a couple hours for help on this. No luck.</p>

<p>Following the docs <a href="https://docs.craftcms.com/v3/asset-bundles.html" rel="nofollow noreferrer">here</a>.</p>

<p>My first two passes were unsuccessful so I deleted everything and started over. </p>

<p>1) I created a plugin scaffolding with a single controller and successfully registered that plugin. I did not edit anything in that plugin.</p>

<p>2) I created the file "FooBundle.php" in the following folder structure:</p>

<pre><code>recoveryfinder
--myPlugin
  --src
    --FooBundle.php
</code></pre>

<p>3) I edited the contents of FooBundle.php to be exactly the docs:</p>

<pre><code>&lt;?php
namespace ns\prefix;

use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;

class MyPluginAsset extends AssetBundle
{
    public function init()
    {
        // define the path that your publishable resources live
        $this-&gt;sourcePath = '@ns/prefix/resources';

        // define the dependencies
        $this-&gt;depends = [
            CpAsset::class,
        ];

        // define the relative path to CSS/JS files that should be registered with the page
        // when this asset bundle is registered
        $this-&gt;js = [
            'script.js',
        ];

        $this-&gt;css = [
            'styles.css',
        ];

        parent::init();
    }
}
</code></pre>

<p>Lastly I added the following line after my {% extends "base.html" %} in my index.html. My first two lines of index.html look like this:</p>

<pre><code>{% extends "base.html" %}
{% do view.registerAssetBundle("ns\\prefix\\FooBundle") %}
</code></pre>

<p>When I refresh my site index page I get:</p>

<blockquote>
  <p>ReflectionException</p>
  
  <p>Class ns\prefix\FooBundle does not exist</p>
</blockquote>

CC BY-SA 4.0
2018-05-06T01:37:44.830Z
How about making it `class FooBundle extends AssetBundle`
kr37
CC BY-SA 4.0
2018-05-06T13:48:20.317Z
I get the same error.
Eric Snyder
<craft3>
Trouble getting an asset bundle registered
# Trouble getting an asset bundle registered

(Asked by: username_0 on 2018-05-05)

I have searched for a couple hours for help on this. No luck.
Following the docs here.
My first two passes were unsuccessful so I deleted everything and started over. 
1) I created a plugin scaffolding with a single controller and successfully registered that plugin. I did not edit anything in that plugin.
2) I created the file "FooBundle.php" in the following folder structure:
recoveryfinder
--myPlugin
  --src
    --FooBundle.php

3) I edited the contents of FooBundle.php to be exactly the docs:
sourcePath = '@ns/prefix/resources';

        // define the dependencies
        $this->depends = [
            CpAsset::class,
        ];

        // define the relative path to CSS/JS files that should be registered with the page
        // when this asset bundle is registered
        $this->js = [
            'script.js',
        ];

        $this->css = [
            'styles.css',
        ];

        parent::init();
    }
}

Lastly I added the following line after my {% extends "base.html" %} in my index.html. My first two lines of index.html look like this:
{% extends "base.html" %}
{% do view.registerAssetBundle("ns\\prefix\\FooBundle") %}

When I refresh my site index page I get:

ReflectionException
Class ns\prefix\FooBundle does not exist

**Tags:** craft3
> **Comments:**
> **username_1**: How about making it `class FooBundle extends AssetBundle`  
> **username_0**: I get the same error.  

---

## 1 answers

### Answer by username_2 on 2018-05-06. Score: 2 | Accepted answer

Because your `FooBundle` has the classname `MyPluginAsset`rename your class to `FooBundle` and it should work (if your namespace is correct, since your information are not really detailed as always)

The docs are not supposed to be a place for copy paste but a source for information.

> **Comments:**
> **username_0**: OK. So it is a namespace/classname error. Thanks for the pointer in the right direction. Namespaces are new to me. My last PHP work was in 4.x.  
> **username_0**: "The docs are not supposed to be a place for copy paste but a source for information.". Yep, I understand. I am still learning/rebuilding my knowledge after being out of PHP a long time. I'm really sorry for my lack of knowledge. I appreciate your patience and willingness to share and help.  
> **username_2**: It's not your fault. Craft docs are not that good. Some things are well explained there (that's why I always refer to those) and many questions here can be solved by looking in the documentation but for most things it's better/easier to look at yii2 instead of Craft  
> **username_3**: I had the same problem, but I corrected the namespace, the name of the file I had changed already. But I am still facing the same error. :(  

---

