javascript - Nodejs 导出聚合引发语法错误
问题描述
我有许多较小的模块构成服务器的完整 API,每个模块都在它自己的文件中。但是,从单独的文件中导入每个模块相当烦人,因此,我想使用导出聚合来简单地从单个中央模块导入它们。
根据 MDN,该export
语句应该能够处理以下聚合语法:
// Aggregating modules
export * from …; // does not set the default export
export * as name1 from …;
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
export { default } from …;
但是,我一直无法使用这种导出语法;特别是export * as name1 from ...
语法,它会引发Unexpected export specifier type
错误。
我能够使用的上述唯一形式是export * from ...
,但这并不是特别有用......
这就是我在模块中导出 API 的方式:
// user.js - more modules export APIs the same way
export const loginWithEmail = ({ params }) => { /* ... */ }
export const loginWithPhoneNumber = ({ params }) => { /* ... */ }
// ... more exports
这就是我在中央模块中导出这些模块的方式
// api.js - resides in the same location as the separate modules
export * as User from "./user";
export * as Vehicle from "./vehicle";
// ... more exports
有人可以帮我弄清楚我做错了什么吗?
该环境由 VSCode 1.41、NodeJS 13、Expo SDK36、React 16.9、React-Native 0.61、JSX、ES8+ 和 eslint+babel-eslint 组成。
解决方案
推荐阅读
- javascript - b-table 中的可单击列在第一次单击时未注册排序图标
- c# - 用 AppendLine 删除一个额外的空行?
- xml - XSLT 根据条件拆分 XML 文件
- reactjs - React Native 从数据库中选择默认值
- reactjs - 如何在 React 单元测试中不渲染某些组件
- phpmyadmin - Phpmyadmin Xampp 列宽适合页面,如何调整列宽?
- python - Google Sheets python api - 如何在保留工作表格式的同时将值写入工作表?
- php - 为什么我的网站联系表不起作用?
- asp.net-mvc - 如果成功,ASP.NET MVC 在重定向之前显示消息
- bash - 无法在 vimrc 中添加插件