导入@supermap/iclient-leaflet ,b编译时出现BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.

问题内容:

ERROR in ./node_modules/elasticsearch/src/lib/host.js 11:9-31
Module not found: Error: Can't resolve 'querystring' in 'E:\PC_lijin2\coding\supermap\web\vue\leaflet\Leaflet-master\leaflet_x\node_modules\elasticsearch\src\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "querystring": require.resolve("querystring-es3") }'
        - install 'querystring-es3'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "querystring": false }


ERROR in ./node_modules/elasticsearch/src/lib/log.js 7:10-24
Module not found: Error: Can't resolve 'url' in 'E:\PC_lijin2\coding\supermap\web\vue\leaflet\Leaflet-master\leaflet_x\node_modules\elasticsearch\src\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
        - install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "url": false }


ERROR in ./node_modules/elasticsearch/src/lib/utils.js 5:16-31
Module not found: Error: Can't resolve 'util' in 'E:\PC_lijin2\coding\supermap\web\vue\leaflet\Leaflet-master\leaflet_x\node_modules\elasticsearch\src\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
        - install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "util": false }

解决:

  • 解决报错问题1(只能解决报错,编译时忽略包,但若项目需要依赖包作为运行环境,虽能编译成功,但还是无法支持项目正常运行)

在项目的根目录下的vue.config.js配置文件下配置如下的resolve内容:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack:{
    resolve: {
      fallback: {
        crypto: false,
        url: false,
        querystring: false,
        util: false
      }
    }
  }
})
  • 解决报错问题2(在编译时,将忽略的包也进行编译,同时也需要安装缺失的包),在项目的根目录下的vue.config.js配置文件下配置如下的resolve内容:
npm install querystring-es3
npm install url
npm install elasticsearch #此项可忽略
npm install util
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack:{
    resolve: {
      fallback: {
        //crypto: false,
        // url: false,
        url: require.resolve("url/"),
        // querystring: false,
        querysting: require.resolve("querystring-es3"),
        util: require.resolve("util/")
      }
    }
  }
})
Logo

前往低代码交流专区

更多推荐