NodeJs - SyntaxError Cannot use import statement outside a module

嘗試起個新既 NodeJs project 用 import rather than require 時出現以下 Exception..
SyntaxError: Cannot use import statement outside a module

解決方法:
原來只要係 package.json 上 加返以下 property 便可..

"type": "module",

hope you find it useful

Chi Yau
Chi Yau
Software Developer / App Developer

Interest to share knowledge / experience