[英]How to get untyped npm modules to play nicely with webpack
I am receiving Invalid module name in augmentation
errors from webpack for a couple of library *.d.ts
files I am including in my project. 我收到来自webpack的Invalid module name in augmentation
错误的Invalid module name in augmentation
我在项目中包含了几个库*.d.ts
文件。
An example is from leaflet-draw which has the following module declaration at the top of it's d.ts file: 一个例子来自leaflet-draw,它在d.ts文件的顶部有以下模块声明:
import * as L from 'leaflet';
declare module 'leaflet' {
interface MapOptions {
drawControl?: boolean;
}
Full error is: 完整错误是:
Invalid module name in augmentation. 增强中的模块名称无效。 Module 'leaflet' resolves to an untyped module at 'C:\\Users***\\Documents\\GitHub***\\node_modules\\leaflet\\dist\\leaflet-src.js', which cannot be augmented. 模块'leaflet'解析为'C:\\ Users *** \\ Documents \\ GitHub *** \\ node_modules \\ leaflet \\ dist \\ leaflet-src.js'中的无类型模块,无法扩充。
I am not entirely sure what to do about this, I dont want to be modifying the d.ts files themselves since these are maintained externally. 我不完全确定如何处理这个问题,我不想自己修改d.ts文件,因为这些是外部维护的。
I am using the latest version of webpack (3.11.0) and ts-loader (3.5.0). 我使用的是最新版本的webpack(3.11.0)和ts-loader(3.5.0)。
My tsconfig compiler options are as follows: 我的tsconfig编译器选项如下:
"compilerOptions": {
"target": "es5",
"sourceMap": true,
"outDir": "./dist",
"rootDir": "../",
"noImplicitAny": false,
"noImplicitThis": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"pretty": true,
"removeComments": false,
"allowUnreachableCode": false,
"declaration": false,
"allowJs": true,
"module": "commonJs",
"typeRoots" : ["./typings/index.d.ts", "../../node_modules/@types"]
}
I appreciate any help anyone can provide to help me understand the error further and how to resolve it f possible. 我感谢任何人提供的任何帮助,以帮助我进一步了解错误以及如何解决它。
Thanks 谢谢
You need to put your import statement inside the declare module. 您需要将import语句放在declare模块中。
declare module '@hyperapp/router' {
import { VNode } from 'hyperapp'
export function Link(props: LinkProps): VNode<LinkProps>
...
}
I had the same error when trying to add the declaration file above (wrote by @m0a whose PR has not been accepted) when the the import statement was on the first line of the file -- which feels most natural. 当导入语句位于文件的第一行时,我尝试添加上面的声明文件时遇到了同样的错误(由@ m0a编写,其PR未被接受) - 这感觉最自然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.