Version
22.16.0
Platform
Linux DESKTOP-TJ5RQRK 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
module
What steps will reproduce the bug?
Run the script below.
const fs = require('node:fs')
fs.mkdirSync('./test-dir')
fs.writeFileSync('./test-dir/package.json', JSON.stringify({
name: 'test-dir',
main: './main.js',
exports: './exports.js'
}), 'utf-8')
fs.writeFileSync('./test-dir/main.js', 'module.exports = "main"\n')
fs.writeFileSync('./test-dir/exports.js', 'module.exports = "exports"\n')
const result = require('./test-dir')
console.log(`result: ${result}`)
Another case
const fs = require('node:fs')
fs.mkdirSync('./node_modules/test-dir/foo', { recursive: true })
fs.writeFileSync(
'./node_modules/test-dir/foo/package.json',
JSON.stringify({
name: 'test-dir',
main: './main.js',
exports: './exports.js',
}),
'utf-8',
)
fs.writeFileSync(
'./node_modules/test-dir/foo/main.js',
'module.exports = "main"\n',
)
fs.writeFileSync(
'./node_modules/test-dir/foo/exports.js',
'module.exports = "exports"\n',
)
const result = require('test-dir/foo')
console.log(`result: ${result}`)
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
result: exports is output.
What do you see instead?
result: main is output.
Additional information
The behavior is aligned to what it is written in the docs.
But AFAIK this is the only place where exports field is ignored and main field is used. I wonder if this is an intended behavior.
Version
22.16.0
Platform
Subsystem
module
What steps will reproduce the bug?
Run the script below.
Another case
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
result: exportsis output.What do you see instead?
result: mainis output.Additional information
The behavior is aligned to what it is written in the docs.
But AFAIK this is the only place where
exportsfield is ignored andmainfield is used. I wonder if this is an intended behavior.