Importing UMD built module using webpack leads to Critical Dependency errors

瘦欲@ 提交于 2019-12-05 14:54:23

I ran into the same issue and wanted to share two ways to workaround the problem:

If the consumed package consists of one single module, just like before the 1.0.1 version of the jsonc-parser, you can add the following to your webpack.config.js:

module: {
    rules: [
        // your rules come here. 
    ],
    noParse: /jsonc-parser|other-umd-packages/
},

If the consumed package consists of multiple files, one can use the umd-compat-loader as a workaround. Add the umd-compat-loader loader to your package.json and configure the following rule in the webpack.config.js:

module: {
    rules: [
        // other rules come here.
        {
            test: /node_modules[\\|/](jsonc-parser|other-umd-packages)/,
            use: { loader: 'umd-compat-loader' }
        }
    ]
},

Some hints on how to properly use the test, can be found here. Finally, but not least, the credit goes to the OP of the workaround.

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