You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#303
I mentioned HMR in the mentioned issue. When I perform a restart, I will use require('some.[mjs | cjs]'). If this location is an mjs file, there is a certain probability of encountering an error. This is because I am referencing an ESM file within a CJS module. We have a simple reproduction case.
index.cjs
require('./form.mjs');
form.mjs
// This is a demo provided by Formidable.importhttpfrom'node:http';importformidable,{errorsasformidableErrors}from'formidable';constserver=http.createServer(async(req,res)=>{if(req.url==='/api/upload'&&req.method.toLowerCase()==='post'){// parse a file uploadconstform=formidable({});letfields;letfiles;try{[fields,files]=awaitform.parse(req);}catch(err){// example to check for a very specific errorif(err.code===formidableErrors.maxFieldsExceeded){}console.error(err);res.writeHead(err.httpCode||400,{'Content-Type': 'text/plain'});res.end(String(err));return;}res.writeHead(200,{'Content-Type': 'application/json'});console.log(fields,files);res.end(JSON.stringify({ fields, files },null,2));return;}// show a file upload formres.writeHead(200,{'Content-Type': 'text/html'});res.end(` <h2>With Node.js <code>"http"</code> module</h2> <form action="/api/upload" enctype="multipart/form-data" method="post"> <div>Text field title: <input type="text" name="title" /></div> <input type="submit" value="submit" /> </form> `);});server.listen(8080,()=>{console.log('Server listening on http://localhost:8080/ ...');});
If I now run tsx run.cjs, I will receive an error.
const form = formidable({});
^
TypeError: (0 , import_formidable.default) is not a function
at Server. (d:\code\mono\devview\demo.mjs:7:18)
at Server.emit (node:events:513:28)
at Server.emit (node:domain:489:12)
at parserOnIncoming (node:_http_server:1091:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
Node.js v18.16.0
Expected behavior
Changing form.mjs to form.ts allowed the code to execute smoothly. I believe this may be an issue with a certain loader file.
Problem
#303
I mentioned HMR in the mentioned issue. When I perform a restart, I will use require('some.[
mjs | cjs
]'). If this location is an mjs file, there is a certain probability of encountering an error. This is because I am referencing an ESM file within a CJS module. We have a simple reproduction case.index.cjs
form.mjs
If I now run
tsx run.cjs
, I will receive an error.TypeError: (0 , import_formidable.default) is not a function
at Server. (d:\code\mono\devview\demo.mjs:7:18)
at Server.emit (node:events:513:28)
at Server.emit (node:domain:489:12)
at parserOnIncoming (node:_http_server:1091:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
Node.js v18.16.0
Expected behavior
Changing
form.mjs
toform.ts
allowed the code to execute smoothly. I believe this may be an issue with a certain loader file.Minimal reproduction URL
https://stackblitz.com/edit/node-xbupi5?file=package.json,form.mjs
Version
^3.12.1
Node.js version
v18.16.0
Package manager
npm
Operating system
Windows
Contributions
The text was updated successfully, but these errors were encountered: