In webpack how do I fix 'import declarations may only appear at top level of a module'?

后端 未结 4 590
灰色年华
灰色年华 2020-12-11 16:18

Webpack builds successfully and I can browse to my webpage. However, the Javascript fails, saying: \'import declarations may only appear at top level of a module\'

B

4条回答
  •  旧巷少年郎
    2020-12-11 16:50

    If you're following the guide on https://webpack.js.org , you might not realise that site is only documenting Webpack version 2 or later, not Webpack 1. One of the new features of Webpack 2 is that it has native ES6 import, export and System.import.

    You need to install Webpack 2 first:

    npm install --save-dev webpack@2.2.0-rc.1
    

    If you want to see a list of all Webpack releases, run:

    npm show webpack versions --json
    

提交回复
热议问题