Encountering "Uncaught SyntaxError: Identifier 'module' has already been declared"
I'm new to arktype and don't have a deep understanding of how web bundlers/etc work, so this may be a bit of a noob question.
I'm using npm and parcel in our code base with several other package dependencies. The error above is referring to this line of code:
https://github.com/arktypeio/arktype/blob/main/ark/type/scope.ts#L338
My best guess is there some conflict because my project references some package that uses CommonJS modules and therefore declaring it's own module. Any idea if this is possible and/or any other insight?
Thanks in advance!
Tom
GitHub
arktype/ark/type/scope.ts at main · arktypeio/arktype
TypeScript's 1:1 validator, optimized from editor to runtime - arktypeio/arktype
7 Replies
Hey! Seems like a reasonable guess.
ArkType only supports ESM so if your project is using CJS, I wouldn't expect it to work in general. Maybe a reasonable idea to not have a variable called
module
though just in case. I normally access it as type.module
anywaysHi ArkDavid, thanks for the reply!
My project does target ES6, but something in it is still defining a global module. Unfortunately, that's where my lack of experience leaves me lol
I can try to start from a simple project then add dependencies one by one until it breaks.
I'd say if you want to work around it for now you could just add some hacky transform to replace that string with a different name when you bundle
It is only used in one place internally. In
ark/type/keywords
, we reexport it as arkModule
. So you could just rename it to that maybe and delete the alias depending on how the bundler works?I will change this for next release just because I don't think having a top-level export called
module
is really needed anywaysgotcha, ok. Thank you! I can look into tweaking the code for now.
Ok good luck! Thanks for letting me know about this 👍 Definitely the kind of thing that is tough to think about/test for internally