0

I am working on code that is a mixture of JS and TS, using TypeScript 3.8. I wrote the following line:

export * as Easing from './easing';

Which should be fair game in TypeScript 3.8. However, I am compiling using Webpack, and I am not using ts-loader, only babel-loader with the TypeScript preset, and it seems like Babel does not support this syntax. I'm getting this error:

ERROR in ./src/index.ts
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/laptou/projects/my-project/src/index.ts: Unexpected export specifier type
 30 |     default as Clock, addUpdateListener, after, chain, clock, infinite, tween
 31 | } from './clock';
 32 | export * as Easing from './easing';
    |        ^^^^^^^^^^^
 33 | export type { Tween, TweenOptions, TweenStatus } from './tween';
 34 | export { default as InterpolateTween } from './tween/interpolate'

How can I fix this?

laptou
  • 4,262
  • 1
  • 18
  • 33

2 Answers2

1

I've asked this question before here: namespace export from index.js

import * as Easing from './easing';
export { Easing }
Adam
  • 41,349
  • 10
  • 58
  • 78
  • I guess that does the trick. I was looking for a Babel extension/option that would simply add the syntax, since it is already supported by TypeScript. Thank you anyway. – laptou May 10 '20 at 21:13
  • If you're using babel, you MAY have to add a plugin, such as `@babel/plugin-proposal-export-namespace-from` – Alexandre Dias Dec 03 '20 at 17:01
0

try this

// ./some/someFile.ts

export function util1 () {
...
}

export function util2 () {
...
}

export function util3 () {
...
}

An on your index or any file you import yow functions

// ./some/index.ts

export * as utils from "./someFile";

If by any means you get some problems.

Change your index.ts to:

import * as utils from "./someFile";

export { utils };

or we could used the old but always trusted default form:

// ./some/someFile.ts

function util1 () {
...
}

function util2 () {
...
}

function util3 () {
...
}

export default {
   util1,
   util2,
   util3
}

at the index

import utils from "./someFile";
export { utils };

// or
export { default as utils } from "./someFile";
Ernesto
  • 1,911
  • 1
  • 9
  • 18
  • Just adding that on older versions of Babel, `export * from "..."` is not supported, you would need to add a plugin, such as `@babel/plugin-proposal-export-namespace-from` – Alexandre Dias Dec 03 '20 at 17:02