How to use with require in admin.js
Solved
Plugin Development
-
Hi
I building plugin, I don't know how to add therequire.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) => { console.log(ui.item.user.uid) }) settings.load('quickstart', $('.quickstart-settings')); $('#save').on('click', saveSettings); }; function saveSettings() { settings.save('quickstart', $('.quickstart-settings'), function () { app.alert({ type: 'success', alert_id: 'quickstart-saved', title: 'Settings Saved', message: 'Please reload your NodeBB to apply these settings', clickfn: function () { socket.emit('admin.reload'); }, }); }); } 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?
Thanks! -
@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 https://community.nodebb.org/post/76984 -
-
Copyright © 2024 NodeBB | Contributors