My current project is utilizing typescript and has been constructed using webpack.
Within my project, there exists a typings file originating from a third-party library, located at
node_modules/@types/libname/custom.d.ts
. This particular file contains a namespace declaration along with several associated types:
declare namespace MyNamespace {
export type A = ...;
}
In order to reference and utilize these types within my typescript code, I must include an import declaration somewhere in the application like so:
import 'libname'
When compiled with tsc, this import resolves correctly to
node_modules/@types/libname/custom.d.ts
, allowing for successful compilation. However, when attempting to build with webpack, an error occurs due to the inability to comprehend this specific import statement:
ERROR in ./Index.tsx
Module not found: Error: Can't resolve 'libname' in 'C:\<path_to_index_file>'
@ ./Index.tsx 44:0-32
I have made attempts to address this issue by adding an alias within my webpack configuration as follows:
resolve: {
alias: Object.assign({
'libname$': path.resolve(__dirname, 'node_modules/@types/libname/custom.d.ts'),
}
},
Unfortunately, this approach has proven unsuccessful as webpack struggles to interpret the syntax of the specified file, prompting inquiries regarding missing loaders.
How can I resolve this situation and enable webpack to recognize this typings import statement effectively?
The version of webpack being utilized is 4.41.6
.
Thank you!