#help

1 messages · Page 1 of 1 (latest)

velvet panther
#

you need to be in a module to use import

#

specify "type": "module" in your package.json

simple sundial
#

@wide sandal You shouldn't need type: "module" to use import statements in TS. That switches your project over to native ESM, but you shouldn't need to do that. It can be simpler to have TS output CommonJS syntax instead via module: "CommonJS" in the tsconfig

true valley
#

why simpler?

simple sundial
#

I believe native ESM in node is still a little new and experimental - unless it's gotten a ton better in the last few months, I think it's a bit of a headache to get it set up and working right. Whereas "TS compiles to CJS" has been the standard approach for years.

#

The only issue you're likely to hit with compile-to-CJS is 1) if you need a very specific feature like top-level await or 2) a few libraries have intentionally dropped support for it in their latest versions.

true valley
#

And more libraries will

#

There shouldn't be issuses with native ESM, if you want to compile to ESM only then do it

#

At least I idk about issuses with ESM

simple sundial
#

People having issues with native ESM has been a pretty common theme here over the last year or two.

true valley
#

What kind of issuses?

simple sundial
#

Tooling issues, library support issues, configuration issues.

#

Anyways, this is kind of a tangent here. If you want to recommend people use native ESM, sure. But let's not tell people that they need type: "module" to write import in Typescript.

true valley
#

Neither let's tell them they need to compile to CJS

simple sundial
#

I didn't say they need to.

#

I said "can be simpler" and I still think that's generally true. Maybe that'll change over time.

true valley
#

How making TS output CJS could be simpler? And simpler in terms of what?

wide sandal
simple sundial
#

@wide sandal No, you can't do that either way - you need to compile the TS code to JS before you run it.

wide sandal
simple sundial
#

You generally don't install a package like ts-node globally, the executable is installed into node_modules/.bin.

#

You should be able to run it with npm exec ts-node or you can make a package.json script (where binaries are loaded automatically)

wide sandal
#

So it would give me import error if I remove type module rn

simple sundial
#

What was already there?

wide sandal
#

@simple sundial when I do npm exec ts-node Error: Cannot find module './ts-node'

wide sandal
simple sundial
#

If you're trying to run TS files directly without compiling them, it won't work even with type: "module", as soon as you add a type annotation, it'll fail.

simple sundial
#

I'm not sure why npm exec isn't working.

wide sandal
simple sundial
#

Did you locally install ts-node?

wide sandal
#

I did npm I ts-node

simple sundial
#

Yeah, that should work. So is there a ts-node file inside node_modules/.bin?

#

You could also try npx instead of npm exec - maybe your npm version is older than npm exec?

wide sandal
simple sundial
#

Are you running this command in the root of your project?

wide sandal
#

It's a startup command of my pterodactyl panel

simple sundial
#

I don't know what that is.

wide sandal
#

Think just its a vps

simple sundial
#

A third option is to just put ts-node in your start script:

"scripts": {
   "start": "ts-node app.ts"
}
wide sandal
#

Oke

#

:/home/container$ ts-node src/index.ts
/entrypoint.sh: line 16: ts-node: command not found

#

@simple sundial

simple sundial
#

Okay, something is strange with your environment, all of these things should work.

wide sandal
#

I don't think it's strange enough

#

Dosent work in my vsc too

simple sundial
#

Not sure what to say. These things definitely work in a properly setup environment.

simple sundial
#

I've given three that should work; I can't really debug your environment.

wide sandal
simple sundial
#

Sorry, not really interested in creating accounts and actually trying to debug in a system I don't know anything about.

wide sandal
simple sundial
#

At worst, if node_modules/.bin/ts-node exists you should be able to run that directly form the .bin folder.

wide sandal
#

Do I do npm exec node_modules/.bin/ts-node @simple sundial

simple sundial
#

No, if npm exec isn't working for some reason, you'd just run the executable directly

simple sundial
#

node_modules/.bin/ts-node app.ts

wide sandal
simple sundial
#

It's a unix shell command.

wide sandal
#

I don't have shell sadly

simple sundial
#

Well then I really don't know anything about the environment you're trying to run this in.

#

I guess you should look into seeing how to run npm-installed programs as pterodactyl startup commands

wide sandal
#

@simple sundial worked but shows cannot compile typescript

simple sundial
#

Like... your program has compiler errors?

#

Or the command is still not running?

wide sandal
#

@simple sundial everything done just 1 help

#

src/events/ticketCreate.ts:525:14 - error TS2304: Cannot find name 'interaction'.

#

Why is interaction not named

simple sundial
#

Hard to say without seeing the relevant code.

wide sandal
#

I'm unsure why it's undefined

simple sundial
#

Where is interaction declared?

wide sandal
#

Above of it was defined

simple sundial
#

Can you show that code?

wide sandal
# simple sundial Where is `interaction` declared?

export default new Event(
"interactionCreate",
async (interaction: SelectMenuInteraction) => {
//Return if it's not a button
if (!interaction.isSelectMenu()) {
return;
}
//Return if it does not match ticket customIDs
if (!client.ticketNames.includes(interaction.values[0])) {
return;
}

#

Whole file?

simple sundial
#

I don't really want to see an entire 500-line file, are you sure the line erroring is still inside the function that has the interaction argument?

wide sandal
#

Yes

#

I think I have added something extra or whatever

#

I am not able to find

wide sandal
#

@simple sundial you can close this all done

simple sundial
#

@wide sandal You can send !resolved and it'll close.

#

Glad you figured it out.

#

!resolved