Epic Posted February 28, 2022 Report Posted February 28, 2022 (edited) 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! Edited February 28, 2022 by Epic Quote
Dr. McKay Posted February 28, 2022 Report Posted February 28, 2022 I don't see a problem with that change. https://github.com/DoctorMcKay/node-steam-user/releases/tag/v4.23.0 Epic 1 Quote
Epic Posted February 28, 2022 Author Report Posted February 28, 2022 It's working great now - no issues! Thanks for the change, really appreciate it Dr. McKay 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.