You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@lance Do you think we could simply remove const from our enums here?
That should be part of it. But I think the resolution should be more comprehensive. I found this article a good read on the problem, as I was unaware of exactly why this was an issue. https://ncjamieson.com/dont-export-const-enums/
We should add "isolatedModules": "true" to our tsconfig.json. I did this locally, and it actually exposes a number of problems besides just this.
❯ npm run build
> cloudevents@5.3.1 build /home/lanceball/src/github.com/cloudevents/sdk-javascript
> tsc --project tsconfig.json && tsc --project tsconfig.browser.json && webpack
src/index.ts:20:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
20 CloudEventV1,
~~~~~~~~~~~~
src/index.ts:21:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
21 CloudEventV1Attributes,
~~~~~~~~~~~~~~~~~~~~~~
src/index.ts:25:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
25 Headers,
~~~~~~~
src/index.ts:27:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
27 Binding,
~~~~~~~
src/index.ts:28:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
28 Message,
~~~~~~~
src/index.ts:29:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
29 Deserializer,
~~~~~~~~~~~~
src/index.ts:30:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
30 Serializer,
~~~~~~~~~~
src/index.ts:33:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
33 KafkaEvent,
~~~~~~~~~~
src/index.ts:34:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
34 KafkaMessage,
~~~~~~~~~~~~
src/index.ts:36:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
36 MQTTMessage,
~~~~~~~~~~~
src/index.ts:39:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
39 TransportFunction,
~~~~~~~~~~~~~~~~~
src/index.ts:40:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
40 EmitterFunction,
~~~~~~~~~~~~~~~
src/index.ts:43:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
43 Options,
~~~~~~~
src/message/kafka/index.ts:14:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
14 KafkaMessage,
~~~~~~~~~~~~
src/message/kafka/index.ts:15:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
15 KafkaEvent
~~~~~~~~~~
src/message/mqtt/index.ts:10:3 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
10 MQTTMessage,
~~~~~~~~~~~
Found 16 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! cloudevents@5.3.1 build: `tsc --project tsconfig.json && tsc --project tsconfig.browser.json && webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the cloudevents@5.3.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/lanceball/.npm/_logs/2022-02-09T20_02_30_244Z-debug.log
By simply changing tsconfig.json to use "isolatedModules": "true", it seems TypeScript transpiles to the correct JavaScript.
exports.CloudEvent=exports.Version=void0;constuuid_1=require("uuid");/** * An enum representing the CloudEvent specification version */varVersion;(function(Version){Version["V1"]="1.0";Version["V03"]="0.3";})(Version=exports.Version||(exports.Version={}));
Activity
github-actions commentedon Jan 29, 2022
This issue is stale because it has been open 30 days with no activity.
jketcham commentedon Feb 9, 2022
I'm running into this issue as well in a Typescript project being transpiled with babel.
For reference, it looks like there are two places where
const enumis being used:sdk-javascript/src/event/cloudevent.ts
Line 17 in 2ac731e
sdk-javascript/src/transport/protocols.ts
Line 10 in 80d987c
Could a change to remove the
constdeclaration from those enums be accepted?Or I think setting
preserveConstEnumstotruemay fix the problem too, info on that option here: https://www.typescriptlang.org/tsconfig#preserveConstEnums.I tried both changes in a fork and all tests passed if anyone is interested in taking a look. I can open a PR if either change is reasonable.
grant commentedon Feb 9, 2022
@lance Do you think we could simply remove
constfrom our enums here?Seeing a downstream issue.
lance commentedon Feb 9, 2022
That should be part of it. But I think the resolution should be more comprehensive. I found this article a good read on the problem, as I was unaware of exactly why this was an issue. https://ncjamieson.com/dont-export-const-enums/
We should add
"isolatedModules": "true"to our tsconfig.json. I did this locally, and it actually exposes a number of problems besides just this.lance commentedon Feb 9, 2022
By simply changing tsconfig.json to use
"isolatedModules": "true", it seems TypeScript transpiles to the correct JavaScript.fix: use `isolatedModules: true` in tsconfig.json
fix: use `isolatedModules: true` in tsconfig.json (#469)