#class not exporting

67 messages · Page 1 of 1 (latest)

zealous elk
#

here is how In am exporting a class in my server.ts file and here is how I am importing it in another js file, I have compiled ts to js using "tsc -t es5 server.ts" command. but whenever I try to run node testserver.js which imports the exported class it gives me this error ?

import { Wsmt } from './server.js'
^^^^
SyntaxError: The requested module './server.js' does not provide an export named 'Wsmt'

wicked citrus
#

could you show what server.js contains?

zealous elk
#

The second image where I am exporting the class is the file server.ts

#

(Which I compile to server.js using the tsc cmd)

wicked citrus
#

so something's probably going wrong in server.js

zealous elk
#

Oh ok wait

zealous elk
wicked citrus
#

wait

#

exports.Wsmt is undefined???

#

does it get reassigned at the bottom?

#

wait

#

maybe try removing -t es5

zealous elk
#

Ok

wicked citrus
#

are you using type: module?

zealous elk
zealous elk
#

Ping on replying

wicked citrus
#

surely at least es6

#

anyway you need at least es6 for the modules

zealous elk
wicked citrus
#

maybe module: es6 too (or whichever way you specify that for commandline)

#

hm

#

might want to use one of the default configs

zealous elk
#

How do I do that? Pretty new to ts

wicked citrus
zealous elk
#

What is that like a package?

wicked citrus
#

yeah

#

youd want to extend one of the preset tsconfigs from there

zealous elk
#

What are presets?

wicked citrus
zealous elk
#

Ok will do thanks

wicked citrus
# zealous elk What are presets?

not an actual term (apologies for the confusion), just implying that those should have all the appropriate options set for most common setups

#

so like, if youre using ESM youd just install the node16+esm version (with or without strictest) and youd be ready to go

#

*keep in mind that you still have to have a tsconfig.json - see the page for details

#

*also keep in mind that if you provide any configuration flags on the commandline, it ignores your tsconfig

solar sierra
zealous elk
#

why do I get this error? Error: Cannot find module 'jsonwebtoken'

#

ok so installed jsonwebtoken without the @types thingy and it works now, what does @types signify?

wicked citrus
#

actually, they're third-party (community contributed) type definitions

zealous elk
#

So basically people contributing time to add type definitions to js libs?

wicked citrus
#

yup

zealous elk
#

where are they hosted?

wicked citrus
zealous elk
#

So when u run npm install @types/libname mom downloads from there?

#

Npm*

wicked citrus
#

not quite

#

the types are automatically published from there, to @types/libname

#

because DefinitelyTyped owns the @types namespace

zealous elk
#

So npm hosts it on their website from there?

wicked citrus
#

well

#

all npm packages are hosted on npm

zealous elk
#

But the type definitions are done by other people that is not he lib owner?

#

The

wicked citrus
#

DefinitelyTyped basically does npm publish @types/libname whenever the community contributors decide to do a release

wicked citrus
#

i mean, it's a completely different package

#

might be useful to think of it as, they're all (kinda sorta) subpackages of a @types package

zealous elk
#

Ohh ok starting to make sense

wicked citrus
solar sierra