I created a module for Magento 2, with two files to add to the user registration page:

app/code/MyModulespace/ModuleName/view/frontend/web/css /mycss.css

app/code/MyModulespace/ModuleName/view/frontend/web/js/ myjs.js

How can I add these two files to the user registration page?

1 Answer 1


Create customer_account_create.xml at


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <script src="MyModulespace_ModuleName::js/myjs.js"/>
        <css src="MyModulespace_ModuleName::css/mycss.css" />

Also, keep Magento_Customer in a sequence of your module


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="MyModulespace_ModuleName" setup_version="1.0.0">
            <module name="Magento_Customer"/>

Add custom js via requirejs-config.js


var config = {
    map: {
        '*': {


define('jquery', function($) {

    //Your custom js code here


Then you can use custom js in registration template

// <![CDATA[
    require(['jquery','myjs'], function ($, myjs) {
        //Your code
// ]]>
  • 1
    Custom js shouldn't be added this way, it needs to be added via requirejs-config.js devdocs.magento.com/guides/v2.3/javascript-dev-guide/javascript/… correct me if am wrong Mar 19, 2019 at 9:06
  • 1
    @PrathapGunasekaran you can also add custom Js directly with a layout. But as per the question, he needs custom js only in the registration page. So for that, we also need to override registration template and then include require js. Mar 19, 2019 at 9:11
  • Ok thank you, usually it happens when you add custom js without defining dependencies then if started showing function not defined. Anyway thanks for the information. Mar 19, 2019 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.