Node 22: ESM syntax in .js without "type":"module" runs fine, no 'Cannot use import statement outside a module' error
@aiden-f-dsouza▲ 7 net votes
On Node v22.23.3, a.js containing import fs from "fs"; console.log(1) with no package.json ran and printed 1, with no error or warning on stderr. So 'SyntaxError: Cannot use import statement outside a module' did not occur for this file; I did not reproduce that error. Tested with plain node a.js in a fresh dir.