使用vue的i18n 出现很多warning提示

问题描述

使用vue的i18n 出现很多warning提示
Module parse failed: Unexpected token (1:10)
You may need an appropriate loader to handle this file type.
| {“version”:3,”sources”:[“webpack:///webpack/universalModuleDefinition”

问题出现的环境背景及自己尝试过哪些方法

"vue": "^2.5.16",
"vue-i18n": "^7.3.2",
"vue-loader": "^13.3.0",
"vue-router": "^3.0.1",

方法:

修改vue的版本没有什么用

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

Module parse failed: Unexpected token (1:10)
You may need an appropriate loader to handle this file type.
| {"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 9917dc3397fa2a2ff2ba","webpack:///./src/locale/lang.js","webpack:///external {\"root\":\"Vue\",\"commonjs\":\"vue\",\"commonjs2\":\"vue\",\"amd\":\"vue\"}","webpack:///./src/locale/lang/pt-PT.js"],"names":["root","factory","exports","module","require","define","amd","self","this","__WEBPACK_EXTERNAL_MODULE_1__","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","lang","isServer","window","iview","langs","locale","Vue","$isServer","select","placeholder","noMatch","loading","table","noDataText","noFilteredDataText","confirmFilter","resetFilter","clearFilter","datepicker","selectDate","selectTime","startTime","endTime","clear","ok","datePanelLabel","month","month1","month2","month3","month4","month5","month6","month7","month8","month9","month10","month11","month12","year","weekStartDay","weeks","sun","mon","tue","wed","thu","fri","sat","months","m1","m2","m3","m4","m5","m6","m7","m8","m9","m10","m11","m12","transfer","titles","source","target","filterPlaceholder","notFoundText","modal","okText","cancelText","poptip","page","prev","next","total","item","items","prev5","next5","goto","rate","star","stars","tree","emptyText","default"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,QACA,mBAAAC,eAAAC,IACAD,OAAA,uBAAAJ,GACA,iBAAAC,QACAA,QAAA,gBA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ACTC,MAAO,SACPC,GAAI,YACJC,eAAgB,mBAChBC,MAAO,MACPC,OAAQ,UACRC,OAAQ,YACRC,OAAQ,QACRC,OAAQ,QACRC,OAAQ,OACRC,OAAQ,QACRC,OAAQ,QACRC,OAAQ,SACRC,OAAQ,WACRC,QAAS,UACTC,QAAS,WACTC,QAAS,WACTC,KAAM,MACNC,aAAc,IACdC,OACIC,IAAK,MACLC,IAAK,MACLC,IAAK,MACLC,IAAK,MACLC,IAAK,MACLC,IAAK,MACLC,IAAK,OAETC,QACIC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,GAAI,MACJC,IAAK,MACLC,IAAK,MACLC,IAAK,QAGbC,UACIC,QACIC,OAAQ,SACRC,OAAQ,WAEZC,kBAAmB,gBACnBC,aAAc,kBAElBC,OACIC,OAAQ,YACRC,WAAY,YAEhBC,QACIF,OAAQ,YACRC,WAAY,YAEhBE,MACIC,KAAM,kBACNC,KAAM,iBACNC,MAAO,QACPC,KAAM,OACNC,MAAO,QACPC,MAAO,mBACPC,MAAO,oBACPP,KAAM,QACNQ,KAAM,UACNlF,EAAG,IAEPmF,MACIC,KAAM,UACNC,MAAO,YAEXC,MACIC,UAAW,gBAKvB,oDAtGA9G,EAAA,IAsGA+G,SAAQtF,aAEOA","file":"pt-PT.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"vue\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"iview/locale\", [\"vue\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"iview/locale\"] = factory(require(\"vue\"));\n\telse\n\t\troot[\"iview/locale\"] = factory(root[\"Vue\"]);\n})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_1__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/dist/locale/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 23);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 9917dc3397fa2a2ff2ba","// using with vue-i18n in CDN\r\n/*eslint-disable */\r\nimport Vue from 'vue';\r\nconst isServer = Vue.prototype.$isServer;\r\n\r\nexport default function (lang) {\r\n    if (!isServer) {\r\n        if (typeof window.iview !== 'undefined') {\r\n            if (!('langs' in iview)) {\r\n                iview.langs = {};\r\n            }\r\n            iview.langs[lang.i.locale] = lang;\r\n        }\r\n    }\r\n};\r\n/*eslint-enable */\n\n\n// WEBPACK FOOTER //\n// ./src/locale/lang.js","module.exports = __WEBPACK_EXTERNAL_MODULE_1__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"root\":\"Vue\",\"commonjs\":\"vue\",\"commonjs2\":\"vue\",\"amd\":\"vue\"}\n// module id = 1\n// module chunks = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30","import setLang from '../lang';\r\n\r\nconst lang = {\r\n    i: {\r\n        locale: 'pt-PT',\r\n        select: {\r\n            placeholder: 'Selecionar',\r\n            noMatch: 'Não encontrado',\r\n            loading: 'A carregar'\r\n        },\r\n        table: {\r\n            noDataText: 'Sem dados',\r\n            noFilteredDataText: 'Sem dados filtrados',\r\n            confirmFilter: 'Confirmar',\r\n            resetFilter: 'Limpar',\r\n            clearFilter: 'Todos'\r\n        },\r\n        datepicker: {\r\n            selectDate: 'Selecione a data',\r\n            selectTime: 'Selecione a hora',\r\n            startTime: 'Hora inicial',\r\n            endTime: 'Hora final',\r\n            clear: 'Limpar',\r\n            ok: 'Confirmar',\r\n            datePanelLabel: '[mmmm] de [yyyy]',\r\n            month: 'Mês',\r\n            month1: 'Janeiro',\r\n            month2: 'Fevereiro',\r\n            month3: 'Março',\r\n            month4: 'Abril',\r\n            month5: 'Maio',\r\n            month6: 'Junho',\r\n            month7: 'Julho',\r\n            month8: 'Agosto',\r\n            month9: 'Setembro',\r\n            month10: 'Outubro',\r\n            month11: 'Novembro',\r\n            month12: 'Dezembro',\r\n            year: 'Ano',\r\n            weekStartDay: '1',\r\n            weeks: {\r\n                sun: 'Dom',\r\n                mon: 'Seg',\r\n                tue: 'Ter',\r\n                wed: 'Qua',\r\n                thu: 'Qui',\r\n                fri: 'Sex',\r\n                sat: 'Sáb'\r\n            },\r\n            months: {\r\n                m1: 'Jan',\r\n                m2: 'Fev',\r\n                m3: 'Mar',\r\n                m4: 'Abr',\r\n                m5: 'Mai',\r\n                m6: 'Jun',\r\n                m7: 'Jul',\r\n                m8: 'Ago',\r\n                m9: 'Set',\r\n                m10: 'Out',\r\n                m11: 'Nov',\r\n                m12: 'Dez'\r\n            }\r\n        },\r\n        transfer: {\r\n            titles: {\r\n                source: 'Origem',\r\n                target: 'Destino'\r\n            },\r\n            filterPlaceholder: 'Pesquise aqui',\r\n            notFoundText: 'Não encontrado'\r\n        },\r\n        modal: {\r\n            okText: 'Confirmar',\r\n            cancelText: 'Cancelar'\r\n        },\r\n        poptip: {\r\n            okText: 'Confirmar',\r\n            cancelText: 'Cancelar'\r\n        },\r\n        page: {\r\n            prev: 'Página anterior',\r\n            next: 'Próxima página',\r\n            total: 'Total',\r\n            item: 'item',\r\n            items: 'itens',\r\n            prev5: 'Voltar 5 páginas',\r\n            next5: 'Avançar 5 páginas',\r\n            page: '/page',\r\n            goto: 'Ir para',\r\n            p: ''\r\n        },\r\n        rate: {\r\n            star: 'Estrela',\r\n            stars: 'Estrelas'\r\n        },\r\n        tree: {\r\n            emptyText: 'Sem dados'\r\n        }\r\n    }\r\n};\r\n\r\nsetLang(lang);\r\n\r\nexport default lang;\n\n\n// WEBPACK FOOTER //\n// ./src/locale/lang/pt-PT.js"],"sourceRoot":""}

你期待的结果是什么?实际看到的错误信息又是什么?

不再出现这个错误提示
webpack-internal:///263:175 [HMR] bundle has 31 warnings
client.js?7955:176 ./node_modules/cargo-ant/dist/locale/ar-EG.js.map…

回答:

在另外的环境中无错 拷贝相关的文件发现组件并没有什么问题
最后发现在使用的index.js文件有些许不同修正后即可

require('xxx/dist/locale/' + lang ).default ====>require('xxx/dist/locale/' + lang + '.js').default

暂无评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注