The "Not implemented" error occurs when attempting to use a feature, method, or API that has not been implemented in the current environment, library, or Node.js version. This can happen with custom stream implementations, platform-specific functions, or browser APIs in testing environments.
This error indicates that a method, function, or feature you're trying to use is not available or has not been implemented in your current runtime environment. Unlike other errors that signal bugs or misconfigurations, this error explicitly states that the functionality simply doesn't exist yet or isn't supported on your platform. The error can occur in several contexts: when extending built-in classes without implementing required methods (like custom streams), when using platform-specific Node.js APIs on unsupported operating systems, when testing with JSDOM which doesn't implement all browser APIs, or when using features that are defined in specifications but not yet available in your Node.js version. This is distinct from "method not found" errors - the method exists but intentionally returns an error because the implementation is missing or not supported in your specific environment.
Check the error stack trace to determine which method is not implemented:
Error: Not implemented
at Readable._read (internal/streams/readable.js:...)
at Readable.read (internal/streams/readable.js:...)Look for the method name and context where the error occurs. This will tell you whether it's a stream implementation, file system operation, or API call.
If you're extending built-in Node.js classes, ensure you implement all required methods. For custom streams:
const { Readable } = require('stream');
class MyReadable extends Readable {
constructor(options) {
super(options);
this.data = ['chunk1', 'chunk2', 'chunk3'];
}
// REQUIRED: Implement _read method
_read(size) {
const chunk = this.data.shift();
if (chunk) {
this.push(chunk);
} else {
this.push(null); // Signal end of stream
}
}
}For custom Writable streams, implement _write():
const { Writable } = require('stream');
class MyWritable extends Writable {
_write(chunk, encoding, callback) {
console.log(chunk.toString());
callback(); // Signal completion
}
}When testing with Jest and JSDOM, mock browser APIs that aren't implemented:
// In your test setup file or specific test
describe('Component tests', () => {
beforeAll(() => {
// Mock window.open
global.open = jest.fn();
// Mock localStorage if not implemented
const localStorageMock = {
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
};
global.localStorage = localStorageMock;
// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
});
});If a feature is not implemented in your environment, find alternatives:
For file:// URLs with fetch, use the fs module instead:
// Instead of: fetch('file:///path/to/file.txt')
const fs = require('fs').promises;
const content = await fs.readFile('/path/to/file.txt', 'utf8');For platform-specific functions, check platform and provide fallbacks:
const os = require('os');
function getNetworkInterfaces() {
try {
return os.networkInterfaces();
} catch (err) {
if (err.code === 'ENOSYS') {
console.warn('networkInterfaces not supported on this platform');
return {}; // Return safe fallback
}
throw err;
}
}Some features may not be implemented in older Node.js versions. Check your version:
node --versionReview the Node.js changelog to see if the feature you need is available in newer versions:
# Upgrade Node.js using nvm
nvm install --lts
nvm use --lts
# Or using package manager
# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# macOS
brew update
brew upgrade nodeAfter upgrading, verify the feature is available in your version of Node.js.
For file system operations that fail with ENOSYS, handle platform differences:
const fs = require('fs').promises;
const path = require('path');
async function createSymlink(target, linkPath) {
try {
await fs.symlink(target, linkPath);
} catch (err) {
if (err.code === 'ENOSYS') {
console.log('Symlinks not supported, copying file instead');
await fs.copyFile(target, linkPath);
} else {
throw err;
}
}
}On Windows, ensure you have appropriate permissions or use junction points instead:
// Use 'junction' type for directories on Windows
if (process.platform === 'win32') {
await fs.symlink(target, linkPath, 'junction');
}The ERR_METHOD_NOT_IMPLEMENTED error code is specifically used in Node.js core to indicate intentionally unimplemented functionality. When building libraries that need to work across different Node.js versions, use feature detection rather than version checks:
// Feature detection pattern
const hasFileURLSupport = (() => {
try {
new URL('file:///test');
return true;
} catch {
return false;
}
})();For custom implementations, consider using the NotImplementedError pattern to make errors more explicit:
class NotImplementedError extends Error {
constructor(methodName) {
super(`Method ${methodName} is not implemented`);
this.name = 'NotImplementedError';
this.code = 'ERR_METHOD_NOT_IMPLEMENTED';
}
}
class BaseClass {
doSomething() {
throw new NotImplementedError('doSomething');
}
}When working with JSDOM in tests, you can configure it to throw errors or return safe defaults for unimplemented features using the virtualConsole option to suppress warnings if they're expected. For file system limitations like ENOSYS on FAT/NTFS partitions in Linux, consider using ext4 partitions for development or implementing fallback strategies that copy files instead of creating symlinks when necessary.
Error: Listener already called (once event already fired)
EventEmitter listener already called with once()
Error: EACCES: permission denied, open '/root/file.txt'
EACCES: permission denied
Error: Invalid encoding specified (stream encoding not supported)
How to fix Invalid encoding error in Node.js readable streams
Error: EINVAL: invalid argument, open
EINVAL: invalid argument, open
TypeError: readableLength must be a positive integer (stream config)
TypeError: readableLength must be a positive integer in Node.js streams