简体   繁体   中英

Vue: Module parse failed when using "export * as" in TypeScript

I have an index.ts file to export all of my helpers functions. To import them in a more convenient way I want to use the export as functionality of TypeScript 3.8.

So this is my code:

// index.ts
export * from './logging';
export * as TypeHelper from './types';
export * as ValidationHelper from './validation';

This is the error I get when running npm run serve :

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

How can I fix this?

According to Mozilla, that syntax is not in the current spec. That would be possibly ES12

export * from …; // does not set the default export
export * as name1 from …; // Draft ECMAScript® 2O21

For now, you can import them, and then reexport them.

import * as TypeHelper from './types';
export TypeHelper;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM