arrow_backBACK TO DRILLS
Blue BeltarchitecturePREMIUM
The Module That Wasn't Really There
This client component imports a Node.js built-in module and calls a method on it inside a click handler.
REACT_MODULE // 0x42
'use client';
import fs from 'fs';
export default function FileReader() {
const handleClick = () => {
const stream = fs.createReadStream('/data/report.csv');
stream.on('data', (chunk) => console.log(chunk));
};
return <button onClick={handleClick}>Read File</button>;
}The import succeeds, but clicking the button throws "Module 'fs' has been externalized for browser compatibility." Why does the failure happen only on the method call?