4

I'm trying to set up a project where there is a need for an angular client with a minimal node server on the backend, using typescript.

Ideally I'd like to have a folder structure similar to

/
/dist : angular client (--prod) files
/server : node js files (created by typescript)
/tests : server-side test scripts
/src/client: angular typescript
/src/server: node typescript
/src/tests: node typescript test scripts
/src/common: common files shared between node & angular (interface defintions, utils etc)

I am really struggling with trying to create a tsconfig.json file for each "folder".

Errors I get include root issues, modules not found etc

The main problems I am getting are to do with the dreaded

"error TS6059: File 'common/interfaces/cell.ts' is not under 'rootDir' 'server/'. 'rootDir' is expected to contain all source files"

When building / compiling the server, is it possible to take the common folder and move it underneath the server folder, so it is found ?

I would have thought that this is a common requirement (and if it isn't, what is the best practice ? ;) )

I would appreciate your help in setting up the correct settings in the appropriate tsconfig.json files

2 Answers 2

1

you can definitly have multiple typescript definitions for each folder. For node to be able to have common functionionalty like fs or path you will need to set the module to commonjs.

I think you can use rootDirs in this scenario.

here is using

 "rootDirs": [
      "./src",
      "../shared/src"
    ],
Sign up to request clarification or add additional context in comments.

Comments

0

You should not have a tsconfig.json file in every folder. The tsconfig.json is used as the TypeScript compiler configuration. That is, it is the file that basically tells angular how to compile everything to javascript, since browsers can't run Typescript, which is what Angular uses. You only should have one file for the configuration, and it tells the entire app how to compile. As for the structure, it can be setup in any way that you like, but your config must point to the correct files.

3 Comments

Hmm. Perhaps I have been misled (or more likely, misunderstood) by Angular-cli - their default project has a tsconfig.json in /, and another tsconfig.app.json in "/src/app" which extends the config in root
You definitely can have multiple tsconfig.json files in a single project, using config inheritance. Whether you should in this case is another matter.
yeah, I think a node project needs a module of "commonjs" whereas angular needs "es2015"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.