Hey,
I am currently working on an electron app which is relying on your 'steam-user' module, and am running into an issue with webpack when requiring the module.
Error: Cannot find module './clientmetrics.json'
The file in question is located under 'node_modules/steam-user/protobufs/generated' and get's required by the '_load.js' file (auto-generated by '../scripts/generate-protos.js') in the same directory. The issue with webpack is it is running in build-time and thus cannot handle dynamic variables - since the 'load' function ('_load.js') gets executed with the filename as parameter webpack cannot require the JSON files.
I fixed it by editing the '_load.js' file and passing the required files as a paramter to the 'load' function:
mergeObjects(Schema, load(require('./clientmetrics.json')));
//... same for all other files
function load(filename){
return require('protobufjs').Root.fromJSON(filename);
}
I guess you would also need to edit the 'generate-protos.js' file under '../scripts':
FS.readdirSync(__dirname + '/../protobufs').forEach((filename) => {
if (!filename.match(/\.proto$/)) {
return;
}
let filenameWithoutExtension = filename.replace('.proto', '');
let cmdLine = PBJS_COMMAND_LINE.replace(/%s/g, filenameWithoutExtension);
console.log(cmdLine);
ChildProcess.execSync(cmdLine);
loader += `mergeObjects(Schema, load(require('./${filenameWithoutExtension}.json')));\n`; // FIX HERE
let protoDefinition = require(Path.join(GENERATED_DIR, `${filenameWithoutExtension}.json`));
if (protoDefinition.nested) {
FS.writeSync(typesFile, `///////////////////////////////////////////////\n// ${filenameWithoutExtension}.proto\n///////////////////////////////////////////////\n\n`);
FS.writeSync(typesFile, writeTypedef(protoDefinition.nested));
}
});
//load function:
function load(filename) {
return require('protobufjs').Root.fromJSON(filename); // FIX HERE
}
Don't know if there would be anything else to change - just skipped through the file.
Do you think the fix is appropriate and could be implemented in your module? Or do you have another idea?
Thanks in advance!