Solved How to use with require in admin.js

  • Hi
    I building plugin, I don't know how to add the require.main.require('./src/user') to admin.js (ACP settings)

    const User = require.main.require('./src/user');
    define('admin/plugins/quickstart', ['settings', 'autocomplete'], function (settings, autocomplete) {
    	var ACP = {};
    	ACP.init = function () {
    		autocomplete.user($('#username'), (ev, ui) => {
    		settings.load('quickstart', $('.quickstart-settings'));
    		$('#save').on('click', saveSettings);
    	function saveSettings() {'quickstart', $('.quickstart-settings'), function () {
    				type: 'success',
    				alert_id: 'quickstart-saved',
    				title: 'Settings Saved',
    				message: 'Please reload your NodeBB to apply these settings',
    				clickfn: function () {
    	return ACP;

    there is error in first line
    Uncaught TypeError: Cannot read properties of undefined (reading 'require') at admin.js:1

    How to do it?

  • GNU/Linux Admin

    @yehonatan-albert You are not able to require server-side libraries from the client-side. You will need to make an API call from the client-side to do what you need to do.

  • @julian thanks!
    I successed with plugin socket

  • Topic has been marked as a question  Y Yehonatan Albert 
  • Topic has been marked as solved  Y Yehonatan Albert 

Suggested Topics

  • 2
  • 5
  • 1
  • 3
  • 3
| |