Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网页包+;巴别塔&x2B;ES2015,意外令牌导入_Javascript_Webpack_Babeljs - Fatal编程技术网

Javascript 网页包+;巴别塔&x2B;ES2015,意外令牌导入

Javascript 网页包+;巴别塔&x2B;ES2015,意外令牌导入,javascript,webpack,babeljs,Javascript,Webpack,Babeljs,我知道这里有很多类似的话题 我试图自己解决问题,但我搞砸了 我用 崇高的 Livereload(升华软件包、Windows应用程序和chrome扩展) 崇高服务器 然后Chrome控制台向我展示: Navigated to http://localhost:8080/es6/ Hello world! (from webpack) with an autimatic update bundle.js:73 Uncaught SyntaxError: Unexpected toke

我知道这里有很多类似的话题

我试图自己解决问题,但我搞砸了

我用

崇高的

Livereload(升华软件包、Windows应用程序和chrome扩展)

崇高服务器

然后Chrome控制台向我展示:

Navigated to http://localhost:8080/es6/
Hello world! (from webpack) with an autimatic update        bundle.js:73 
Uncaught SyntaxError: Unexpected token import                 index.js:3 
我尝试了很多方法,但都不适合我

所有npm安装都是本地的

//index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>ES6</title>
    </head>
    <body>
        <script type="text/javascript" src="./.build/bundle.js"></script>
        <script type="text/javascript" src="./app/index.js"></script>
    </body>
</html>
我尝试“fellowship”“fellowship.js”“/fellowship”“/应用程序/fellowship”

没有人工作

//app/fellowship.js

const fellowship = ['frodo', 'Samwise', 'Gandalf'];
const total = fellowship.length;
export { fellowship, total };
/LRC

{
  "plugins": [
    "check-es2015-constants",
    "transform-es2015-block-scoping"
  ]
}
{
  "presets": ["es2015"]
}
/package.json

{
  "name": "es6",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "transpile-es2015": "babel src -d lib",
  },
  "babel": {
    "preset": [
      "es2015"
    ]
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.23.0",
    "babel-core": "^6.23.1",
    "babel-loader": "^6.4.0",
    "babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "^6.22.0",
    "babel-preset-react": "^6.23.0",
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.4.1"
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  }
}
./webpack.config.js

module.exports = {
    entry: ['./app/index.js'],
    output: {
        path: '.build',
        filename: 'bundle.js'
    }
    module: {
        loaders: [
        {
            loader: 'babel-loader',
            test: /\.js$/,
            exclude: /node_modules/,
        }]
    },
}

可能是因为您正在加载html中的源文件和构建文件。尝试从index.html中删除index.js。如果我删除index.js,index.html将无法正确读取index.js。bundle.js是从index.js编译的,因此不需要同时包含这两个。是否有任何特定的原因使您同时加载这两个文件?index.html无法显示index.js中包含的任何内容。这就是我加载index.js的原因。
module.exports = {
    entry: ['./app/index.js'],
    output: {
        path: '.build',
        filename: 'bundle.js'
    }
    module: {
        loaders: [
        {
            loader: 'babel-loader',
            test: /\.js$/,
            exclude: /node_modules/,
        }]
    },
}