我们正在try 使用新的方法导出和导入带有 node 的ES6模块.js.从package.json
文件中获取版本号对我们来说很重要.下面的代码应该可以做到这一点:
import {name, version} from '../../package.json'
但是,执行时会引发以下错误:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".json" for T:\ICP\package.json imported from T:\ICP\src\controllers\about.js
Is there something we're missing?
Is the extension .json
not supported?
Is there another way to retrieve this information using Node.js 13+?