#wierd unexpected identifier issue

96 messages · Page 1 of 1 (latest)

wide condor
atomic chasm
#

sounds like you're trying to run the .ts directly with node?

#

node doesn't support that

#

you should compile and distribute .js and .d.ts files instead

wide condor
#

oh, ill try it

atomic chasm
#

though, the package seems to already do that

#

you did you install and import the package?

wide condor
#

idk how to emit the types

atomic chasm
#

is this your package?

wide condor
#

yep

#

its a npm package i made

atomic chasm
#

seems like you copied an .npmignore from some unrelated project

wide condor
#

nah, its related

#

i have a wierd file structure

atomic chasm
#

what's with the web/, images/, and root index files then lol

#

ah they're gitignored too

#

is this supposed to be both an application and a library?

#

it feels like a half-assed monorepo lmao

wide condor
#

index is made for testing the package

#

during dev

atomic chasm
#

damn you weren't kidding when you said it was weird

#

you couldve just had a separate folder outside this project lol

#

well, src should be .npmignored, and dist should be .gitignored but not .npmignored

wide condor
#

im confused

#

so tsconfig.json should look like this?:

{
  "compilerOptions": {
    "target": "ES2024",
    "module": "Node16",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "declaration": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "outDir": "./dist",
    "importHelpers": true,
    "rootDir": "./src",
    "declarationDir": "./dist/types",
    "downlevelIteration": true,
  },
  "include": ["./src/**/*"]
}
#

@atomic chasm

#

coz ok, now i have the d.ts files but idk how to link them to the js files

atomic chasm
#

set types to point to ./dist/types/index.d.ts in package.json

#

anyways because of your ignores you don't actually have index.js/index.ts in github or npm lol

#

move the root index.js/ts, web, images stuff to a separate folder, set up an actual project there
remove all that extra stuff from npmignore and gitignore
have the test project depend on a file url to your library project folder

wide condor
#

what do i write inside the index file?

atomic chasm
#

the logic to run the library...?

wide condor
#

yeah

atomic chasm
#

possibly to reexport other stuff

#

index is where people import your library from

wide condor
#

smt like this?

import {ArtfightClient} from './client.js';
import {ClientEvents} from './Enumarables.js';
export {ArtfightClient};
atomic chasm
#

you could do export * from './client.js' directly

wide condor
#

and that's all?

#

also now this:
Cannot write file 'd:/JavaScript/Artfight/dist/types/index.d.ts' because it would overwrite input file.
what should i set as main in the project then?

#

empty?

atomic chasm
wide condor
#

nothing, the message shows up in tsconfig.json

atomic chasm
#

i guess you have to exclude dist specifically?

wide condor
#

wdym

atomic chasm
#

does it show up if you run tsc from the command line?

wide condor
#

nah

atomic chasm
#

oh it's probably just tsserver lag then

wide condor
atomic chasm
#

open the command palette, ctrl+shift+p, and run "restart ts server"

wide condor
#

didnt work

#

also wtf

#

the d.ts file for this exists tho

atomic chasm
#

huh? it shouldn't

#

why is it in backticks

wide condor
#

idk

atomic chasm
#

don't use backticks for imports/exports

wide condor
wide condor
#

the issue is that it would override the input file, so maybe i exclude it somehow?

#

or change it to smt else?

atomic chasm
#

is that issue still popping up?

wide condor
#

yep

atomic chasm
#

but it isn't if you run tsc from the commandline?

wide condor
#

it does

atomic chasm
#

as in the error appears?

wide condor
#

yep

#

error TS5055: Cannot write file 'D:/JavaScript/Artfight/dist/types/index.d.ts' because it would overwrite input file.

atomic chasm
#

so i suppose you would have to exclude dist explicitly then

atomic chasm
#

"exclude": ["./dist/**/*"] or "exclude": ["dist"] in tsconfig

wide condor
wide condor
atomic chasm
#

oh what

#

types was supposed to be set in package.json, not here

#

that's the issue lmao

wide condor
#

xdd

#

ok, no more issues

#

and all should work now?

atomic chasm
#

make sure to set up the index and npmignore/gitignore correctly

#

you'll also have to manually remove dist from git tracking

wide condor
#

oh, like the file?

atomic chasm
#

no, the entire folder

wide condor
#

oh, ok

#

so inside gitignore i ignore dist and inside npmignore src ?

atomic chasm
#

yes

#

and then separate your testing environment out

wide condor
#

delete all the useless stuff u mean?

atomic chasm
#

move it to a separate project, and remove the web/images/index stuff from gitignore and npmignore

wide condor
atomic chasm
#

is that really all you need to export for the consumer?

#

exporting some types you use would probably help a lot

#

so you can use ClientUser or whatever directly instead of ArtfightClient["user"]

#

also i'd recommend adding a build script and putting types next to main in package.json