javascript - 从命令行使用 Node 导入运行 Javascript
问题描述
我对从命令行运行 javascript 有点不熟悉,但我处于需要为松下 AC 使用 NPM 包的情况,该包有一个用于其非官方 API 的包装器。
但是,我想制作一个可以从命令行运行的简单 JS,它将导入 NPM 包。但这只会产生错误:
(node:68628) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/Ronny/Documents/AC/index.js:1
import { ComfortCloudClient } from 'panasonic-comfort-cloud-client'
^^^^^^
SyntaxError: Cannot use import statement outside a module
难道不能这样做吗?
解决方案
它可以使用节点require()
功能
const { ComfortCloudClient } = require('panasonic-comfort-cloud-client')
推荐阅读
- c# - ASP.NET 核心实体框架。如何使用子查询编写异步查询?
- python - 如何保存包括日期在内的 yahooquery 结果?
- processing - 每 40 毫秒处理一次 saveFrame
- amazon-ec2 - 如何在 EC2 中为 RDS 配置出站规则
- reactjs - 使用React 上的重定向器将数据从输入框传递到第二个页面
- angular - 如何使用运算符 from 处理错误 rxjs?
- azure - Azure Service Fabric 内部负载平衡
- python-3.x - Python:Excel的不同维度的字典
- vb.net - 扩大:代表性的变化
- listview - Xamarin.Forms ListView 内的自定义 WebViews,每行计算高度