首页 / 浏览问题 / WebGIS / 问题详情
webpack打包项目出现错误
2EXP 2022年03月10日

使用产品: SuperMap iClient JavaScript 10i(2021)  for Leaflet

操作系统:win10 x64

问题详细描述:项目使用vue,参考开发指南进行配置,在运行是使用webpack打包运行,出现了以下错误提示:

 ERROR  Failed to compile with 1 errors                                                                                                                                                                                                                   上午10:38:36

 error  in ./node_modules/@supermap/iclient-common/iServer/ImageService.js

Module parse failed: Unexpected token (82:25)
You may need an appropriate loader to handle this file type.
|      */
|     search(imageSearchParameter) {
|         var postBody = { ...(imageSearchParameter || {}) };
|         var me = this;
|         var path = Util.convertPath('/search');

 @ ./node_modules/@supermap/iclient-common/iServer/index.js 245:0-42
 @ ./node_modules/@supermap/iclient-common/index.js
 @ ./node_modules/@supermap/iclient-leaflet/index.js
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/index.vue
 @ ./src/views/index.vue
 @ ./src/router/index.js
 @ ./src/main.js

关于webpack.base.conf.js的配置,参照了开发指南中的打包配置:

要如何解决呢?

1个回答

您好,将ES6语法转换成ES5语法的配置,需要根据您的babel版本进行微调,针对您的配置没有生效有以下建议:

  1. 尝试去掉path和__dirname,将其改为resolve("node_modules/@supermap/iclient-common"),另外2行也做类似的改动;
  2. 若第一个建议依然无效,建议您切换babel版本,我本地使用的babel 6x能够在编译时正确进行语法转换,看您的语法使用的是babel 7x。

希望可以帮到您。

2,158EXP 2022年03月10日
 ERROR  Failed to compile with 1 errors                                                                                                                                                                                                                   上午11:49:41

 error  in ./node_modules/@supermap/iclient-leaflet/index.js

Module build failed: ReferenceError: Unknown plugin "@babel/plugin-transform-runtime" specified in "base" at 0, attempted to resolve relative to "C:\\project\\BigScreen\\zzycs\\node_modules\\@supermap\\iclient-leaflet"
    at C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\file\options\option-manager.js:180:17
    at Array.map (<anonymous>)
    at Function.normalisePlugins (C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
    at OptionManager.mergeOptions (C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)
    at OptionManager.init (C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\file\options\option-manager.js:368:12)
    at File.initOptions (C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\file\index.js:212:65)
    at new File (C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\file\index.js:135:24)
    at Pipeline.transform (C:\project\BigScreen\zzycs\node_modules\babel-core\lib\transformation\pipeline.js:46:16)
    at transpile (C:\project\BigScreen\zzycs\node_modules\babel-loader\lib\index.js:50:20)
    at Object.module.exports (C:\project\BigScreen\zzycs\node_modules\babel-loader\lib\index.js:173:20)

 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/index.vue 364:0-58
 @ ./src/views/index.vue
 @ ./src/router/index.js
 @ ./src/main.js

按照第一个建议配置后,旧的错误提示没了,却又弹出这个错误提示,我这是只能切换babel的版本了么?

您好,因为babel7x的版本与babel6x依赖有一些不同,这报错看起来像缺少部分依赖,建议您若是一定要使用babel7x的话,您可以详细阅读https://www.babeljs.cn/docs/v7-migration-api使用教程。

若依然不行的话,建议您尝试切换babel6x,我本地使用的就是babel6x,很简单的配置即可将ES6转换成ES5,若您切换版本的话,建议您参考以下配置:

    "babel-core": "^6.22.1",

    "babel-helper-vue-jsx-merge-props": "^2.0.3",

    "babel-loader": "^7.1.1",

    "babel-plugin-syntax-jsx": "^6.18.0",

    "babel-plugin-transform-runtime": "^6.22.0",

    "babel-plugin-transform-vue-jsx": "^3.5.0",

    "babel-preset-env": "^1.3.2",

    "babel-preset-stage-2": "^6.22.0",

希望可以帮到您。

我的就是按照你这个配置,还是有这个问题,怎么弄呢
...