javascript - SyntaxError: Unexpected token { 同时从文件导入函数
问题描述
我正在尝试创建自己的库来获取天气预报,问题是我在导入函数时遇到问题
我已经尝试过了export function convertDate ...
,但没有成功
这是我得到的错误:
(function (exports, require, module, __filename, __dirname) { import {convertDate} from "./utils/DataManagement";
^
SyntaxError: Unexpected token {
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:696:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
at Function.Module._load (internal/modules/cjs/loader.js:560:3)
at Module.require (internal/modules/cjs/loader.js:665:17)
at require (internal/modules/cjs/helpers.js:20:18)
这是我导入函数的方式:
import {convertDate} from "./utils/DataManagement";
最后,这里是我拥有函数本身的地方,也是我导出它的地方:
function convertDate(date) {
let newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);
let offs = date.getTimezoneOffset() / 60;
let hours = date.getHours();
newDate.setHours(hours - offs);
return newDate;
}
export { convertDate };
解决方案
推荐阅读
- sql-server - SQL 聚合函数 - 计数不同,避免重复
- c++ - C++:告诉用户输入 A、B 或 C,但如果他们输入不同的字符怎么办?
- node.js - 在 NODE-RED 处将 3 个输出转换为一个输入
- php - 发送带附件的 HTML 电子邮件 PHP
- android - Whatsapp上的图像共享不起作用
- jquery - Jquery单击和光标:指针仅针对一个元素
- mongodb - 删除 $sample 之后的重复项
- json - 不使用 json 模块将 JSON 文件读入数据帧
- excel - Excel VBA基于范围返回工作表的顶部单元格地址
- spring - 为什么当我添加安全弹簧依赖项时 Tomcat 不工作?