Node.js SyntaxError:Cannot use import statement outside a module

 今天在測試Node.js的功能時,使用import的語法,執行時出現錯誤:Cannot use import statement outside a module

出錯的程式片段如下:

import express from 'express';

如果修改程式如下,則執行成功:

const express = require('express');

原來在ES6標準釋出後,module成為標準,以export匯出介面,用import引入模組。

但是在之前採用的是的是CommonJS規範,以module.exports匯出介面,用require引入模組。

我的Node.js版本是v16.0.0,我的解決方式是修改package.json,增加語法 "type":"module"



Oracle DB的listener.log清理