importing a package in ES6: “Failed to resolve module specifier ”vue“”

后端 未结 3 1754
刺人心
刺人心 2020-12-11 00:50

Trying to follow some Vue tutorials and I can\'t currently import Vue in a .js file and then import this file in my index.html. This is how I\'m im

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 01:26

    The way you can use ES modules in your Browser directly (as of June 2020) is thus:

    1. Use the ESM version of your dependencies (the one that has import instead of require). For example, Vue ESM version is available at: https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.0-beta.14/vue.esm-browser.js

    2. Make your browser work with the experimental importmap feature. Import maps are a new web recommendation, not yet supported in mainstream browsers. https://wicg.github.io/import-maps/#import-map In Chrome this is under chrome://flags#enable-experimental-productivity-features (latest Chrome versions moved this under chrome://flags#enable-experimental-web-platform-features)

    3. Create an importmap in your HTML file. It only works with inline

      1. Load your own code as an ESM module.
      
      
      1. In your own scripts, and the scripts that you import - you can now successfully import from named modules.

      Full example:

      
      
      
      
      
      
      

提交回复
热议问题