import() breaks in Angular 7.2.3 + Webpack 4.28

孤人 提交于 2019-12-13 03:56:54

问题


I have the following code :

var path = "./relative/path/to/" + fileName + ".json";
import(path).then(cb);

The import works as expected in my Electron demo (which uses Webpack 3.12).

It breaks in my Angular demo (which uses Webpack 4.28).

My Angular demo has the following Webpack config :

module.exports = {
  node: { fs: 'empty' }
};

It produces the following error at runtime :

Unhandled Promise rejection: Cannot find module './resources/symbology/labelTemplates/labelTemplates.json' ; Zone: <root> ; Task: Promise.then ; Value: Error: Cannot find module './resources/symbology/labelTemplates/labelTemplates.json'
    at symbology lazy namespace object:5
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
    at zone.js:889
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601) Error: Cannot find module './resources/symbology/labelTemplates/labelTemplates.json'
...

I tried various changes to my config, but I keep getting the same error.

Am I doing something wrong?

来源:https://stackoverflow.com/questions/54651712/import-breaks-in-angular-7-2-3-webpack-4-28

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!