简体   繁体   English

在 Mapbox 中找不到模块“./grid_control”

[英]Cannot find module './grid_control' from Mapbox

I just changed my application to lazy-load Mapbox like this:我刚刚将我的应用程序更改为延迟加载 Mapbox,如下所示:

    private loadMapBox(): Promise<any> {
        return import("mapbox.js/dist/mapbox")
            .then(m => {
                // When the Mapbox module is loaded, it registers itself as "window.L"
                // but the module's content is not returned in the variable "m".
                this.mapbox = (<any>window).L;
            });
    }

And I started getting this error when trying to run my tests (even though it compiled ok):我在尝试运行测试时开始收到此错误(即使编译正常):

Error: Unable to resolve module [./grid_control] from [/my/path/node_modules/mapbox.js/dist/mapbox.js]
...
Error: Cannot find module './grid_control' from '/my/path/node_modules/mapbox.js/dist'
    at /my/path/node_modules/karma-typescript/src/bundler/resolve/resolver.ts:217:27
    at /my/path/node_modules/browser-resolve/index.js:265:24
    at /my/path/node_modules/resolve/lib/async.js:55:18
    at load (/my/path/node_modules/resolve/lib/async.js:69:43)
    at onex (/my/path/node_modules/resolve/lib/async.js:92:31)
    at /my/path/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:153:21)

When I changed the line:当我换行时:

import("mapbox.js/dist/mapbox")

to:至:

import("mapbox.js")

The tests started working ok.测试开始工作正常。

I don't know much of how Webpack works.我不太了解 Webpack 的工作原理。 Why does the first syntax not work?为什么第一种语法不起作用? I expected that specifying the whole path was ok, for example when you want to read the minified version of 3rd-party library.我希望指定整个路径是可以的,例如当你想阅读 3rd-party 库的缩小版本时。

Also, notice that both syntax work ok for when the application is running, the problem was only in the Karma tests.另外,请注意这两种语法在应用程序运行时都可以正常工作,问题仅出现在 Karma 测试中。

Thanks.谢谢。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM