Hello amit basu,
I understand you are encountering a 400 Bad Request with the specific error {"code": "ServiceError", "message": "path is not defined"} when uploading an image in the Bot Framework Emulator, and the request never reaches your bot's logic.
The error message "path is not defined" is the standard JavaScript ReferenceError message when code tries to use the path variable (typically the Node.js path module) without importing it first.
Even though the error appears in the Emulator, the "ServiceError" wrapper indicates that your bot's server caught an unhandled exception during the request processing (likely in the parsing of the file attachment) and returned this formatted error to the Emulator.
You (or a library you are using) are likely trying to process the uploaded file's metadata (like its name or extension) using the Node.js path module, but the module has not been required at the top of the file.
Example of problematic code:
// Missing: const path = require('path');
// This line will throw "path is not defined"
const extension = path.extname(attachment.name);
Suggesting a workaround to try:
1: Check Your Bot Code for Missing Imports
Search your project files (specifically any files handling file uploads, attachments, or incoming activities) for usages of the word path.
- Look for code like
path.join,path.resolve, orpath.extname. - Ensure that the file containing that code has this line at the very top: JavaScript
const path = require('path');
2: Check Custom Middleware
If you are using any custom middleware to handle file uploads (like multer, formidable, or custom logic to save attachments to a temp folder), check those files specifically. The error is happening early in the pipeline, which suggests it's in the code responsible for parsing the incoming HTTP request.
3: Update Emulator (If the issue is not in your code)
While less likely to produce this specific error message, ensure you are using the latest version of the Bot Framework Emulator to avoid known issues with attachment payload formatting.
Note: Would also recommend enable detailed error logging to confirm exactly where this is crashing, you need to see the full stack trace in your bot's console, not just the JSON response.
Reference:
Please let me know if adding the missing require('path') resolves your issue. If this answer helps, kindly "Accept the answer" to support the community.