首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Vue:在TypeScript中使用"export * as“时模块解析失败

Vue:在TypeScript中使用"export * as“时模块解析失败
EN

Stack Overflow用户
提问于 2020-09-24 19:52:48
回答 1查看 233关注 0票数 0

我有一个index.ts文件来导出我所有的助手函数。为了以更方便的方式导入它们,我想使用TypeScript 3.8的export as功能。

所以这是我的代码:

代码语言:javascript
运行
复制
// index.ts
export * from './logging';
export * as TypeHelper from './types';
export * as ValidationHelper from './validation';

这是我在运行npm run serve时得到的错误

代码语言:javascript
运行
复制
ERROR  Failed to compile with 1 errors                                                                                                                                               13:44:55

error  in ./src/services/helpers/index.ts

Module parse failed: Unexpected token (2:9)
File was processed with these loaders:
 * ./node_modules/cache-loader/dist/cjs.js
 * ./node_modules/@vue/cli-plugin-typescript/node_modules/ts-loader/index.js
 * ./node_modules/eslint-loader/index.js
You may need an additional loader to handle the result of these loaders.
| export * from './logging';
> export * as TypeHelper from './types';
| export * as ValidationHelper from './validation';
| 

 @ ./src/plugins/router/index.ts 3:0-41 92:8-11 98:8-11
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://192.168.179.4:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

Type checking in progress...
No type errors found
Version: typescript 3.9.7

我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-27 12:57:47

根据Mozilla的说法,该语法不在当前规范中。那可能是ES12

代码语言:javascript
运行
复制
export * from …; // does not set the default export
export * as name1 from …; // Draft ECMAScript® 2O21

现在,您可以导入它们,然后重新导出它们。

代码语言:javascript
运行
复制
import * as TypeHelper from './types';
export TypeHelper;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64045868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档