Here is my main.ts
file:
import { enableProdMode, NgModuleRef, Type, NgZone } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { BootstrapPsm } from 'projects/shared/src/lib/service/bootstrap-psm';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import './polyfills';
import './assets/js/libs/pixi.min.js';
import 'foo-dts';
if (environment.production) {
enableProdMode();
}
(Error as any).stackTraceLimit = 100;
const ngZone = new NgZone({ enableLongStackTrace: true });
platformBrowserDynamic()
.bootstrapModule(AppModule, { ngZone })
.then((ref: NgModuleRef<AppModule>) => {
const bootstrap: BootstrapPsm = ref.injector.get<BootstrapPsm>(BootstrapPsm as Type<BootstrapPsm>);
bootstrap.init();
})
.catch((err: Error) => console.error(err));
Additionally, I have a tsconfig.json
file:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"downlevelIteration": true,
"outDir": "./dist/out-tsc",
"sourceMap": false,
"declaration": false,
"module": "amd",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"noImplicitAny": false,
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"paths": {
"foo-dts": ["./projects/shared/src/lib/types/foo-dts"]
},
"resolveJsonModule": true
}
}
While trying to start the development server with ng serve
, I encounter this error message:
ERROR in ./src/main.ts Module not found: Error: Can't resolve 'foo-dts' in 'C:\Users\someUser\gitProjects\user_interface\projects\baseline\src'
.
The contents of the foo-dts
file are:
export {};
declare global {
const ContentQueue: any;
interface Date {
format(value: string): string;
}
interface Window {
...
}
}
Although the interfaces should be imported, they are not. Trying to fix it, I modified the types file like this:
declare module "foo-dts" {
interface Window {
...
};
}
This seemed to resolve the error, but then properties set to this interface were not exported globally, resulting in errors such as:
Property 'FooConfig' does not exist on type 'Window'
.
Even after packaging the file into an npm package and installing it, and importing it using import '@types/foo-dts';
, the same 'module not found' error persisted.
I am struggling to find the correct solution to this issue.