Ts-loader: Does ts-loader support the `export * as <name>` introduced in typescript 3.8?

Created on 27 May 2020  路  5Comments  路  Source: TypeStrong/ts-loader

I'm getting an error when trying to build a project with these kinds of exports, I wonder if its just because its not supported by tsloader.

The particular error:

ERROR in ./libs/riot-api/src/index.ts 4:9
Module parse failed: Unexpected token (4:9)
File was processed with these loaders:
 * ./node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
| export * from './lib/config';
| export * from './generated';
> export * as Static from './lib/static';
| 
There was an error with the build. See above.

Most helpful comment

What is your module setting in tsconfig.json? I was able to reproduce the error using "ES2020" but not if using "ES6". I created a small repo to test this at:

https://github.com/appzuka/ts-loader-es2020-export-demo

As described at https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html Typescript will emit the old syntax if your module target is lower than es2020. The error you are seeing is that webpack/Node do not understand the new syntax. You need to tell ts-loader to transpile down to the old syntax for the build to succeed.

tsc does not complain but if you try to run the code tsc produces you will see the error.

All 5 comments

ts-loader shouldn't need to do anything specific to support this. Does what you're doing work with tsc alone?

Yes it does

Then this is something of a mystery! If you'd like to look into it I'd greatly appreciate it!

What is your module setting in tsconfig.json? I was able to reproduce the error using "ES2020" but not if using "ES6". I created a small repo to test this at:

https://github.com/appzuka/ts-loader-es2020-export-demo

As described at https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html Typescript will emit the old syntax if your module target is lower than es2020. The error you are seeing is that webpack/Node do not understand the new syntax. You need to tell ts-loader to transpile down to the old syntax for the build to succeed.

tsc does not complain but if you try to run the code tsc produces you will see the error.

@appzuka I think that is it, the module setting is esnext which I assume is equivalent to es2020 in this case.

Was this page helpful?
0 / 5 - 0 ratings