anaval
anaval

Reputation: 1138

Typescript folder structure confusing

This is my folder structure:

projectRoot
projectRoot/app
projectRoot/app/main.ts
projectRoot/app/factoryClasses/Person.ts
projectRoot/node_modules/*angular 2 files*

inside my main.ts is an import statement

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

import { Person } from './factoryClasses/Person.ts';//this works
import { Person } from 'factoryClasses/Person.ts';//this doesn't

platformBrowserDynamic().bootstrapModule(AppModule,TestModule);

My main.ts is inside the app/ folder but why is main.ts looking for the file in projectRoot/node_modules/factoryClasses/Person.ts instead of projectRoot/app/factoryClasses/Person.ts? This is from the angular.io quick start by the way.

Upvotes: 0

Views: 342

Answers (1)

Jonathan
Jonathan

Reputation: 40

In your tsconfig.json file, you'll see one of the properties is "moduleResolution". If you have it set to "node" (which the quickstart does unless you've changed it), then is uses nodejs rules for resolving relative paths.

{
  ...
  "moduleResolution": "node",
  ...
}

You can read more about it here.

Upvotes: 1

Related Questions