Can't import ng2 service unless use specific capitalization

63 Views Asked by At

I have created a service in file 'myapi.service.ts' which contains:

export class MyAPIService {

and in my component I import the service as follows:

import { MyAPIService } from '../myapi.service';

But everytime I compile I get this error:

Module '"/myapi.service"' has no exported member 'MyAPIService'.

The problem seems to be capitalizatio.n If I import "MyapiService" instead of "MyAPIService" then it compiles fine. But why? Does ng2 require/force certain capitalization? Shouldn't it use the capitalization I used when creating the class?

1

There are 1 best solutions below

4
On BEST ANSWER

There is no such a thing in Angular or TypeScript. Make sure there is no other mistake somewhere in your code.

Here's a working example

Maybe also (although this is a real edge case), check your webpack config if there's anything going super crazy in there, or you played with the paths property of tsconfig, but most likely it's a much simpler mistake in your code.

Maybe you needed to restart your build watch / dev server too or so as well.

Update

If this is an external dependency (NPM module), then try removing your node_modules folder and running npm install again.

As in comments, this was the case for the OP.