Angular2: Can't find namespace "environment"

I configured tsconfig.json

mine, so for brevity I can use short import paths in my code. For example, I can do import { FooService } from 'core'

instead of forcing something like import { FooService } from '../../../core/services/foo/foo.service'

.

This works fine, except that for some reason I created a new file, one of the import files throws an error:

The namespace could not be found.

This error occurs because of the following line: import { environment } from 'environment';

This is very strange because I have the same import in many other services and none of them throw an error, it only happens in this new file that I created.

This is mine tsconfig.json

:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "paths": {
      "core": ["app/core"],
      "core/*": ["app/core/*"],

      "shared": ["app/shared"],
      "shared/*": ["app/shared/*"],

      "modal": ["app/modal"],
      "modal/*": ["app/modal/*"],

      "environment": ["environment/environment"]// HERE
    },
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

      

As you can see, they are paths

configured correctly. And if they weren't, it wouldn't have worked all this time in other files ...

What's going on here? Does anyone know how to fix this?

+3


source to share


1 answer


SOLVED PROBLEM

I had a typo in my code that caused this. Very hard to find because intellisense doesn't make it stand out.

I have had: url: environment.serverUrl;



When I had to: url: string = environment.serverUrl;

I used the value as a type by accident. Unfortunately,

+3


source







All Articles