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

后端 未结 4 602
灰色年华
灰色年华 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:33

    I had the same problem. You installed ES6. The import fails w/o it.

    Babel file is copied without being transformed

    EDIT:

    By default, Babel 6.x does not perform any transformations. You need to tell it what transformations to run:

    npm install babel-preset-es2015
    

    and run

    babel --presets es2015 proxy.js --out-file proxified.js
    

    or create a .babelrc file containing

    {
        "presets": [
            "es2015"
        ]
    }
    

提交回复
热议问题