A colleague mailed me the following error message when using TypeScript and the ‘import’ syntax to load module:
error TS1147: Import declarations in a namespace cannot reference a module.
Here is the related code. The error was thrown on the import statement:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SampleModule { | |
import * as _ from "lodash"; | |
export class SampleController{ | |
constructor() {...... | |
} | |
} | |
} |
We found the solution quickly. After moving the ‘import’ statements outside the module, the error disappeared:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as _ from "lodash"; | |
module SampleModule { | |
export class SampleController{ | |
constructor() {...... | |
} | |
} | |
} |