In order to use import { readFileSync } from 'fs'
, you have to:
--experimental-modules
flag (in Node.js 10), e.g. node --experimental-modules server.mjs
(see #3 for explanation of .mjs)import
statements, to .mjs
, .js will not work, e.g. server.mjsThe other answers hit on 1 and 2, but 3 is also necessary. Also, note that this feature is considered extremely experimental at this point (1/10 stability) and not recommended for production, but I will still probably use it.
Here's the Node.js 10 ESM documentation.