vue-cli項目中出現“unexpected token import ”時的解決辦法


開啟eslint語法校驗的時候,運行項目會出現“unexpected token import ”這個問題,經過查找后發現是es6語法問題,導致不可以使用import,下面來具體分析一下這個錯誤;

ES6語法的模塊導入導出(import/export)功能,我們在使用它的時候,可能會報錯:

 

 

可以通過以下方式解決

1.安裝@babel/plugin-syntax-dynamic-import --save-dev

1 yarn add eslint-plugin-vue --save-dev

2.配置babel.config.js文件

 

module.exports = {
  "presets": [
    "@vue/app"
  ],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      },
	  "syntax-dynamic-import"
    ]
  ]
}

3.安裝 eslint-plugin-vue

1 yarn add eslint-plugin-vue --save-dev

4.配置eslintrc.js文件

module.exports = {
    root: true,
    parserOptions: {
      sourceType: 'module'
    },
    env: {
      browser: true,
      node: true,
      es6: true,
    },
    parser: "vue-eslint-parser",
    
    rules: {
      'no-console': 'off',
    }
  }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM