【发布时间】:2018-01-31 01:58:36
【问题描述】:
我需要为我的代码创建一个 Hammer 的别名。我在 tsconfig 中添加了路径,如下所示:
{
"compilerOptions": {
"declaration": true,
"noImplicitAny": false ,
"noEmitOnError": true,
"noUnusedLocals": false ,
"noUnusedParameters": false ,
"module": "commonjs",
"moduleResolution": "node",
"target": "ES5",
"outDir": "./lib",
"lib": ["ES5", "ES2015.Promise", "DOM", "ES2015.Collection", "es2016"],
"jsx": "react",
"types": [],
"baseUrl": ".",
"paths": {
"Hammer": ["hammerjs/hammer.js"]
}
},
"include": ["typings/index.d.ts","src/*"]
}
但是在 geo.js 中我仍然收到错误,我有“require(Hammer)”。我错过了什么?
ERROR in ./~/geojs/geo.js
Module not found: Error: Can't resolve 'Hammer' in '/home/chaudhary/tools/jupyterlab/mydev/share/jupyter/lab/staging/node_modules/geojs'
@ ./~/geojs/geo.js 3:27-44
@ ./~/@jupyterlab/geojson-extension/lib/index.js
@ ./build/index.out.js
【问题讨论】:
-
你还需要为 webpack 配置路径:github.com/s-panferov/…
-
@ThomasDevries 谢谢。我正在使用 ts-loader (github.com/TypeStrong/ts-loader),你可以在上面的配置中看到路径。
-
我找到了答案,因为在我的情况下,调用程序正在创建自己的 webpack 配置,现在,我必须将 Hammer 嵌入到 GeoJS 中(在 webpack 配置中将 Hammer 作为外部删除)。
标签: typescript webpack jupyter-lab